• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

System.out.println()

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

May be this is easy question but need confirmation from others.
what is the difference between

System.out.println();
System.out.print()
having these in my code, explain me the scenorios. And can I place (, comma) in these two statements what will happen.
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
System.out.print() will print the argument without a newline.
System.out.println() will print the argument and append a newline at the end so that each invocation to println will be made on its
own line on the output...
Examples:

will output
test of print second test of print
Instead,

will output
test of print
second test of print

HIH

------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
 
suma krishnan
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your explantion, I got it
My second question is I placed (,) statement in my code
print satement working perfectly but println is not, Why?.
 
Valentin Crettaz
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry I don;t know what you mean by "placing" (,) in your code. Could you give me some examples, so that I can help you out, Thanks !

------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
 
suma krishnan
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public class TestContinue {
public static void main(String args[]) {
for ( int i = 0 ; i <2; i++) {
for ( int x=0; x<3; x++) {
if ( i == x) {
continue;
}
System.out.println("i = " + i , " x = " + x);
}
}
}
}
this is giving compilor error,
----------
And this compiling but no output.
public class RightJustify {
private static final String padding =
" "+
" "; // 80 spaces
public static void print(String s, int w) {
Stystem.out.print(padding.substring(0, w - s.length()));
System.out.print(s);
}

public static void print(int i, int w){
print( "" + i, w);
}

public static void main(String arg[]);{

}
}
why this statement has(,) in print statement. And why println
statement negotiating (,),is there special rules I have to know
explain me .
Thanks for previous expln,..
 
Valentin Crettaz
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when printing Strings with System.out.print and System.out.println you can only concatenate String with the "+" operator. There is no such thing as "," operator.
In your example I don't see any "," directly inside the argument of System.out.print or System.out.println.

you can only concatenate String with "+" operator thus "," makes no sense here. You might want to change the code like this

In the second code excerpt print is NOT System.out.print but the static method defined above it printing some padding and the first String argument
HIH

------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
 
suma krishnan
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Valetin
Yes, I got it ,I changed my code like this.
--------------------------------------------
System.out.println("i= " + i + " , x " + x);
---------------------------------------------
Its working very fine.

regards
suma
 
reply
    Bookmark Topic Watch Topic
  • New Topic