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
576
votes
9 answers

Why doesn't println! work in Rust unit tests?

I've implemented the following method and unit test: use std::fs::File; use std::path::Path; use std::io::prelude::*; fn read_file(path: &Path) { let mut file = File::open(path).unwrap(); let mut contents = String::new(); …
ruipacheco
  • 15,025
  • 19
  • 82
  • 138
178
votes
5 answers

Difference between fmt.Println() and println() in Go

As illustrated below, both fmt.Println() and println() give same output in Go: Hello world! But: how do they differ from each other? Snippet 1, using the fmt package; package main import ( "fmt" ) func main() { fmt.Println("Hello…
YulCheney
  • 2,877
  • 2
  • 18
  • 14
147
votes
7 answers

How to print a Vec?

I tried the following code: fn main() { let v2 = vec![1; 10]; println!("{}", v2); } But the compiler complains: error[E0277]: `std::vec::Vec<{integer}>` doesn't implement `std::fmt::Display` --> src/main.rs:3:20 | 3 | println!("{}",…
highfly22
  • 1,691
  • 2
  • 10
  • 11
106
votes
7 answers

Division of integers in Java

This is a basic question but I can't find an answer. I've looked into floating point arithmetic and a few other topics but nothing has seemed to address this. I'm sure I just have the wrong terminology. Basically, I want to take two quantities -…
Ben
  • 54,723
  • 49
  • 178
  • 224
92
votes
5 answers

Kotlin doesn't see Java Lombok accessors?

Using Kotlin 1.0.0 release (compiling in IntelliJ 15). println(myPojoInstance.foo) When it tries to compile code (in IntelliJ or Gradle) that references Lombok based POJOs it gives the error "Cannot access 'foo': it is 'private' in "MyPojo". Which…
Chris Kessel
  • 5,583
  • 4
  • 36
  • 55
84
votes
4 answers

How do I print output without a trailing newline in Rust?

The macro println! in Rust always leaves a newline character at the end of each output. For example println!("Enter the number : "); io::stdin().read_line(&mut num); gives the output Enter the number : 56 I don't want the user's input 56 to be on…
7_R3X
  • 3,904
  • 4
  • 25
  • 43
67
votes
7 answers

difference between System.out.println() and System.err.println()

What is the difference between System.out.println() and System.err.println() in Java?
user354299
  • 2,945
  • 5
  • 20
  • 10
54
votes
11 answers

Print in new line, java

I have following code : System.out.println(" | 1 2 3 4 5 6 7 8 9"); System.out.println("----------------------------"); System.out.println(""); I use println to create a new line. Is it possible to do the same using \n or \r? I…
DarkLeafyGreen
  • 69,338
  • 131
  • 383
  • 601
47
votes
1 answer

println vs System.out.println in Scala

I always thought that Predef.println was merely a shortcut for System.out.println, but apparently I am mistaken, since it doesn't seem to use System.out at all. Why is that so? And how can I do the "redirecting" of System.out below in Scala? scala>…
Kim Stebel
  • 41,826
  • 12
  • 125
  • 142
41
votes
8 answers

IntelliJ System.out.println() - Cannot resolve method println(java.lang.String)

I am using IntelliJ IDEA, learning Java. All went well until yesterday, when the mentioned error occurred. I didn't make any changes. I was looking for the solution the following ways: reboot the pc restart IntelliJ. delete the project directory…
user6479494
  • 1,111
  • 1
  • 8
  • 7
36
votes
5 answers

escape dictionary key double quotes when doing println dictionary item in Swift

I've been playing around with Swift, and just came across an issue. I have the following Dictionary in: var locations:Dictionary = ["current":CLLocationCoordinate2D(latitude: lat, longitude: lng) ]; println("current…
Amir
  • 9,577
  • 11
  • 41
  • 58
32
votes
4 answers

println in scala for-comprehension

In a for-comprehension, I can't just put a print statement: def prod (m: Int) = { for (a <- 2 to m/(2*3); print (a + " "); b <- (a+1) to m/a; c = (a*b) if (c < m)) yield c } but I can circumvent it easily with a dummy…
user unknown
  • 35,537
  • 11
  • 75
  • 121
32
votes
5 answers

How to print multiple variable lines in Java

I'm trying to print the test data used in webdriver test inside a print line in Java I need to print multiple variables used in a class inside a system.out.print function (printf/println/whatever). public String firstname; public String…
Harshini
  • 353
  • 2
  • 6
  • 12
29
votes
1 answer

Why does println! work only for arrays with a length less than 33?

In Rust, this works: fn main() { let a = [0; 32]; println!("{:?}", a); } but this doesn't: fn main() { let a = [0; 33]; println!("{:?}", a); } Compile error: error[E0277]: the trait bound `[{integer}; 33]: std::fmt::Debug` is not…
Nikolai Tschacher
  • 1,639
  • 2
  • 17
  • 24
29
votes
2 answers

How to print well-formatted tables to the console?

I have a program that prints out data that should be printed into a format that looks like a table. However, the table breaks when the numbers are longer than 2. I know about the width parameter in std::fmt, but I can't get my head around…
XAMPPRocky
  • 3,160
  • 5
  • 25
  • 45
1
2 3
41 42