Questions tagged [println]

In programming, `println` generally prints out the arguments given, then moves to a new line for subsequent output.

In programming, println generally outputs the arguments supplied, then moves to a new line for any further output operations. For example, in Java you could write the following:

System.out.print("Hello ");
System.out.println("World");
System.out.println("Goodbye");

And the console would output (with \n representing newline characters):

Hello World\n
Goodbye\n

There are several languages that use the println() method; Others have different syntax that accomplishes the same functionality.

617 questions
-2
votes
3 answers

One or two lines of output?

Suppose I executed the following Java method: public static void print() { System.out.print("This is some text"); System.out.println(); } How many lines of output are printed? What counts as a "line of output"? I would think there are two,…
user700352
  • 165
  • 1
  • 9
-2
votes
3 answers

Magical System.out.println("prompt"); wont display output

The code shown below is my main method of a maze game I am creating. In this main method I have a while loop that goes on until the game is finished. In the while loop I print the maze then ask the user which direction they want to move their…
Singh
  • 301
  • 2
  • 6
  • 16
-3
votes
2 answers

Concat different Streams and print on Java

I'm trying to print a concat Stream that includes String and Integer elements. I've try a few ways, but none of them works. I can't find a proper way to do it on internet. It's just a testing code as you can see: import java.util.stream.*; class…
Shinington
  • 17
  • 1
  • 6
-3
votes
3 answers

Why System.out.println(new String(copyTo))?

I was studying the Java tutorials here: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html However a doubt appeared: Why do I need the new String()? Is there any potential problem of using directly System.out.println(copyTo)? I…
DTK
  • 95
  • 1
  • 9
-3
votes
1 answer

wanting to cut out hidden println in java

int anzZeilen = 9; int anzZahlen = 1; for (int i = 1; i <= 9; i++) { System.out.print(" "); for (int j = 1; j < anzZeilen; j++) { System.out.print(" "); } if (anzZahlen % 2 != 0) { …
tombvo
  • 19
  • 2
-3
votes
1 answer

Loop Exercise: Printing a tree on console using for loops (Stuck on details)

This is an exercise for uni I've been working on but I've been stuck on just one last little problem with the output and I just can't find out why. Goal: User inputs height of tree. It gets printed in the following format: E.g height 4 4| * …
sonti yo
  • 61
  • 1
  • 9
-3
votes
1 answer

can i write a similar class as "System" for printing something?

can i build a user-defined class for printing anything using printstream variable just as "System" class ? so what i did is: import java.io.*; public final class SystemDemo{ public final static InputStream give=null;//the same…
nikhil2000
  • 178
  • 3
  • 15
-3
votes
1 answer

ocaml expression type unmatchings

I have the following loop: let show expr = let rec loop acc = function | `S -> "S"^acc | `K -> "I"^acc | `I -> "I"^acc | `App(a,b) -> (loop acc a)^(loop acc b) | `B -> "B"^acc | `C -> "C"^acc | `Sprim -> "S'"^acc |…
yusuf
  • 3,591
  • 8
  • 45
  • 86
-3
votes
2 answers

How to get LONG print line statements to "spill" onto next line without causing compile error in Java?

Essentially my System.out.printf statement is too long. Rather then cutting some of it off and adding another printf statement is there any way to get it to go to the next line without causing a compile error. My code is as…
Dylan Kelemen
  • 173
  • 2
  • 9
-3
votes
3 answers

How to print two seperate overridden toString messages

Is there a way to print two different overridden toString messages given a particular condition? For example, the following is a simple example where I need to print two different error messages if check value is 0. I have overridden the toString to…
Samuel
  • 395
  • 2
  • 5
  • 20
-3
votes
1 answer

Java Printing Wrong Answer to Arithmetic Equation

System.out.println("3.14 - 5 = " + (3.14 - 5)); This statement shows 3.14 - 5 = -1.8599999999999999 in console when the answer is -1.86. How would I be able to fix this error and what is the reason for the wrong answer being printed in the first…
Kyle
  • 183
  • 1
  • 1
  • 12
-3
votes
2 answers

Can it print anything in main

Im writing a java app at the moment and nothing is being run! I can even print simple System.out.println("hi"); Below is the code. I can see the output window fine. No errors are being returned. Im using netbeans 8.0.2 public class…
-3
votes
2 answers

Println cannot find symbol

Im just started to learn Java and have a problem, hope you can help me. import java.util.Date; public class Main { /** * @param args the command line arguments */ public void main(String[] args) { // TODO code application logic here } Date date =…
Davy
  • 11
  • 3
-3
votes
2 answers

Different ways to print the first 5 multiples of 2 in Java as "*"

I'm trying to write a program that prints the output: ** **** ****** ******** ********** What I came up with: public class Loops { public static void main(String[] args) { for(int i=1; i<=5; i++) { for(int j=0; j
dingbat
  • 1
  • 1
-3
votes
1 answer

Nested FOR loop execution logic - beginner

I have found this code as an example but do not understand how it's executed, mainly for the System.out.println() line item. for ( int i = 1; i <= 5; i++) { for ( int j = 1; j <= i; j++) { System.out.print( i ); } …
akinom
  • 3
  • 1