![]() |
What System.out.println() print out when it has no data?
Hi, so this seems like a very dumbr question...
What does System.out.println(); print out when no data is passed to it? Is it just regular whitespace? It's not a linebreak or space character? I ask because I've got an exam in a few days, and I'm just going over a past paper. Some of the questions say, "If you think nothing is printed out, then write no output.", however, System.out.println(); is placed in such a way that even if, say an loop through an array didn't print anything [meaningful] out, there will always be a System.out.println(); outside of the array to print, but no data is passed to it - kinda to catch people out? I tested this in Eclipse and within the command line area, there is whitespace printed out. Do you believe this would be considered something printed out? |
Code:
System.out.println("begin...");Code:
begin...in short- you could have (and still can for extra practice/combinations) coded this real quick and seen the answer :) you need to expose yourself to as many code situations as possible. edit: the code block for output puts in some extra line breaks after "end..." it would not do extras, just one |
Quote:
I would write that it writes a line break to the console (or a new line feed)... or to be more technical saw there is a line feed or you could even be slightly 'cocky' and say that it prints the escape \n (note not "\n" bc that would be System.out.println("\\n");) |
println is equivalent to using System.out.print(whateverdata + '\n') or System.out.print(whateverdata + "\n"). Java considers \n as a valid linefeed either inline with double quotes similar to C printf, or with single quotes denoting it as a char and not a string. When provided with no data, or data that is empty, it will print only a linefeed.
So: Code:
System.out.println(); |
| All times are GMT +1. The time now is 10:10 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.