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

function of == in println()

String literal1 = "java"; String object = new String("java"); String literal2 = "java"; System.out.println("result 1 = " + (literal1 == object) ); System.out.println("result 2 = " + literal1.equals(object)); System.out.println("result 3 = " +…
Aksh
  • 71
  • 1
  • 7
2
votes
1 answer

error in printing char sequence through println in java

It should show the output as 3 but it is showing a box(Unrecognized symbol). What can be the problem? It is not a compiler problem, I have checked this in different compilers. Also, the error persists in case of int array also. package…
2
votes
2 answers

How to print Binary Tree

I've been trying to switch over to Java from Node and one thing I'm wondering about is how to print an object such as a binary Tree in a similar format to how node would display it. For instance, my binary tree initiation code is as follows: public…
user10109
  • 121
  • 1
  • 3
  • 9
2
votes
1 answer

println in scala using Intellij showing weird behaviour

I'm writing a little program in scala that would simulate a doctors practice. One of the requirements is that a user can set consultations with a doctor. I have implemented a solution that gives you the consultation object if you succeed and also…
2
votes
2 answers

How to make a macro that dynamically prints an integer in hex with leading zeros

I am looking to create a macro that will display a type of number in hex along leading zeros equal to its size. For example, hex!(2u8) will print $02 (leading zero) and hex!(2u16) will print $0002 (16bit leading zeros) This is what I have now, but…
user2936448
  • 335
  • 4
  • 16
2
votes
0 answers

In Swift, how to "print()" like "p" command in lldb

"p variable" command prints all the elements within the variable in lldb. In Swift, just regular print() statement does not do this. A hack would be to loop through the backtrace of the variable and print the elements. I'm curious if there is an…
shle2821
  • 1,856
  • 1
  • 19
  • 26
2
votes
1 answer

Why is there difference between difference of System.out.println(+c1) and System.out.println("c1" = +c1)?

When I use: char c1 = '\u534e'; System.out.println(+c1); Then I get: 21326 But when I use: char c1 = '\u534e'; System.out.println("c1 = " +c1); Then I got the char printed correctly: c1 = 华 What's the problem?
Leo Li
  • 81
  • 1
  • 7
2
votes
2 answers

Println test case : println and expected output are the same, but test failed

Here is the code for a simple test case I am doing right now : private static final ByteArrayOutputStream OUTCONTENT = new ByteArrayOutputStream(); private static final PrintStream OLD_STD_OUT = System.out; @Before public void setUp() { …
2
votes
3 answers

How to override = symbol while converting HashMap to String using toString method?

Below is part of code where map is initialized as: Map map = new HashMap<>(); and the line which I want to modify the output is System.out.println("Price and items "+map.toString()); where the output presently is {100=10,200=5} I…
Chaipau
  • 199
  • 1
  • 5
  • 14
2
votes
2 answers

Java: print double - println or printf

Suppose I have the following code: double median = med(10.0, 12.0, 3.0); //method returns middle number as double Now, I want to write a message stating the median. Can this be done using println(), like the following: System.out.println("Your…
yulai
  • 741
  • 3
  • 20
  • 36
2
votes
5 answers

Arduino How can I print the unsigned long long data

I am trying to print unsigned long long data on Serial monitor but Serial.println() doesn't work because of not a string variable. So I searched on the internet to convert unsigned long long to String. I came up with some solutions but none of…
a-f-a
  • 147
  • 1
  • 3
  • 9
2
votes
1 answer

Changing lines while printing array

I'm trying to read a txt file and print the line opposite. for example: txt: 3 //size of matrix 3 4 5 5 6 7 6 7 8 output should be: 6 7 8 5 6 7 3 4 5 I wrote a program. the program prints: 5 6 7 3 4 5 which is without the…
Loren
  • 95
  • 10
2
votes
1 answer

Alernative to printf("%*s",indent,message) in java?

In C we can specify the amount to space to leave in printf , any similar way to do this in java? For example int space=6; char message[10]="hi"; printf("%*s",space,message); will print hi
Sainath S.R
  • 3,074
  • 9
  • 41
  • 72
2
votes
3 answers

Why my method being called 3 times after System.in.read() in loop

I have started to learn Java, wrote couple of very easy things, but there is a thing that I don't understand: public static void main(String[] args) throws java.io.IOException { char ch; do { System.out.println("Quess the…
BlaszczykB
  • 59
  • 7
2
votes
3 answers

Replace printed out text

I created a command line tool which does some long actions, and I want to notify the user through print statements, like: "10% Done" "20% Done" on what percentage of the operation is done. If I use println, each progress will be printed into a new…
Dániel Nagy
  • 11,815
  • 9
  • 50
  • 58