Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-19-2012, 02:08 PM   PM User | #1
bingowinner
New Coder

 
Join Date: Oct 2011
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
bingowinner is an unknown quantity at this point
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?

Last edited by bingowinner; 05-19-2012 at 02:12 PM..
bingowinner is offline   Reply With Quote
Old 05-19-2012, 02:53 PM   PM User | #2
alykins
Senior Coder

 
alykins's Avatar
 
Join Date: Apr 2011
Posts: 1,608
Thanks: 37
Thanked 183 Times in 182 Posts
alykins will become famous soon enough
Code:
System.out.println("begin...");
for(int i =0; i <=2; i++)
{
  System.out.println("cat");
  System.out.println("nip");
  System.out.println();
}
System.out.println("end...");
output

Code:
begin...
cat
nip

cat
nip

cat
nip

end...
if you are in a class, and having an exam, then that means you should have been trying code, practicing, etc- all that aside- it means you should have an IDE (eclipse, netbeans, etc)

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
__________________

I code C hash-tag .Net
Reference: W3C W3CWiki .Net Lib
Validate: html CSS
Debug: Chrome FireFox IE
alykins is offline   Reply With Quote
Old 05-19-2012, 02:57 PM   PM User | #3
alykins
Senior Coder

 
alykins's Avatar
 
Join Date: Apr 2011
Posts: 1,608
Thanks: 37
Thanked 183 Times in 182 Posts
alykins will become famous soon enough
Quote:
Originally Posted by bingowinner View Post
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?
sorry, just saw that line oops-
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")
__________________

I code C hash-tag .Net
Reference: W3C W3CWiki .Net Lib
Validate: html CSS
Debug: Chrome FireFox IE
alykins is offline   Reply With Quote
Old 05-19-2012, 03:46 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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();
System.out.print('\n');
System.out.print("\n");
Would print three empty lines.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:52 AM.


Advertisement
Log in to turn off these ads.