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
28
votes
2 answers

Is there a way to print to the console in an Android app?

Can I run an Android app through the emulator and make it print strings to my computer's console? By console I mean the standard place you would expect to see a System.out.println() in a normal java application. So if you ran the java application…
Anton
  • 12,285
  • 20
  • 64
  • 84
26
votes
5 answers

Why is this program which loops many times taking time when there is a `println` after the loops?

Here is the small code which I am trying. This program takes good amount of time to execute. While running, if I try to kill it through the terminate button in eclipse, it returns Terminate Failed. I can kill it from terminal using kill -9…
Arnab Biswas
  • 4,495
  • 3
  • 42
  • 60
26
votes
2 answers

java.lang.NullPointerException: println needs a message

I get the errror: java.lang.NullPointerException: println needs a message when I call this method: lst_info = new HashMap(); SystemDatabaseHandler db = new SystemDatabaseHandler(getApplicationContext()); lst_info =…
Laire
  • 1,290
  • 6
  • 22
  • 49
25
votes
2 answers

How do I print variables in Rust and have it show everything about that variable, like Ruby's .inspect?

use std::collections::HashMap; fn main() { let mut hash = HashMap::new(); hash.insert("Daniel", "798-1364"); println!("{}", hash); } will fail to compile: error[E0277]: `std::collections::HashMap<&str, &str>` doesn't implement…
Andrew Arrow
  • 4,248
  • 9
  • 53
  • 80
25
votes
4 answers

How to use println in Swift to format number

When logging-out a float in Objective-C you can do the following to limit your output to only 2 decimal places: float avgTemp = 66.844322156 NSLog (@"average temp. = %.2f", avgTemp); But how do you do this in Swift? And how do you escape other…
sirab333
  • 3,662
  • 8
  • 41
  • 54
23
votes
2 answers

Why does `System.out.println(null);` give "The method println(char[]) is ambiguous for the type PrintStream error"?

I am using the code: System.out.println(null); It is showing the error: The method println(char[]) is ambiguous for the type PrintStream Why doesn't null represent Object?
Kannan Thangadurai
  • 1,117
  • 2
  • 17
  • 36
21
votes
3 answers

Capturing contents of standard output in Java

I am invoking a function that is printing some string in my console/standard output. I need to capture this string. I cannot modify the function that is doing the printing, nor change runtime behavior through inheritance. I am unable to find any…
Shailesh Tainwala
  • 6,299
  • 12
  • 58
  • 69
20
votes
8 answers

What is the equivalent of Java's System.out.println() in Javascript?

I am writing some tests for Javascript code and I need to dump some messages during the compile process when errors are encountered. Is there any equivalent to Java's System.out.println() in Javascript? P.S.: I also need to dump debug statements…
Jérôme Verstrynge
  • 57,710
  • 92
  • 283
  • 453
19
votes
2 answers

Spark losing println() on stdout

I have the following code: val blueCount = sc.accumulator[Long](0) val output = input.map { data => for (value <- data.getValues()) { if (record.getEnum() == DataEnum.BLUE) { blueCount += 1 println("Enum = BLUE : " +…
Edamame
  • 23,718
  • 73
  • 186
  • 320
18
votes
2 answers

What benefits are there with making println a macro?

In this code, there is a ! after the println: fn main() { println!("Hello, world!"); } In most languages I have seen, the print operation is a function. Why is it a macro in Rust?
midnight0s
  • 363
  • 3
  • 14
17
votes
1 answer

why does clojure's map behave that way with println?

Hello I'm learning clojure and I want to understand what's going on, when I type (map println '(1 2 3 4)) I expected something like 1 2 3 4 but I got (1 2 nil 3 nil 4 nil nil) This is just an example I made up. I just want to understand what's…
MLmuchAmaze
  • 379
  • 2
  • 14
16
votes
5 answers

println method - what do the last 2 letters (l & n) stand for?

I guess it's related to println()'s newline functionality ('\n'), but in abbreviated letter-based form, that would be nl rather than ln. Thank you for any comments.
user2911290
  • 1,396
  • 1
  • 16
  • 26
13
votes
6 answers

How to create a println/print method for a custom class

I'm working in Java on a project that requires me to make a few 'container' classes, if you will. Here is a simple version of one: public class Pair{ Object KEY; Object VALUE; public Pair(Object k, Object v) { KEY = k; …
Proxy404
  • 189
  • 1
  • 2
  • 8
13
votes
5 answers

How do I print a list of numbers on each line in clojure?

how can I print a list of n, say 10, numbers on 10 lines? I just learned about loop and recur, but cannot seem to combine a side-effect (println i) with (recur (+ i 1)) in a loop form. Just to be very clear: I'd like output like…
Roger
  • 131
  • 1
  • 3
12
votes
9 answers

Java printing a String containing an integer

I have a doubt which follows. public static void main(String[] args) throws IOException{ int number=1; System.out.println("M"+number+1); } Output: M11 But I want to get it printed M2 instead of M11. I couldn't number++ as the variable is…
Harish Raj
  • 1,565
  • 3
  • 17
  • 27
1
2
3
41 42