Adblock breaks this site

Understanding basics of Java - print and println

Discussion in 'Archives' started by diabl0, Sep 18, 2010.

  1. diabl0

    diabl0 Apprentice
    Banned

    Joined:
    Jul 25, 2008
    Posts:
    902
    Referrals:
    0
    Sythe Gold:
    0
    Understanding basics of Java - print and println

    Hello everybody, I know there are some new users of Java here reading this, and I am sure they have take a look at a line of code and seen:

    and

    and were probably like wtf? Am I right? Well, today I am going to clear up the difference of print, and println for the new users. Okay, lets say you have a code such as:

    but when you go to compile and run it, it will all be on the same line. and your like wtf? How do I get it to the next line? Well that is where println comes in.

    Println stands for Print line, So if you were to write that same line of code above with println instead of print, it would come out such as:

    It would appear as this with println:
    [​IMG]

    Whereas print would show:
    [​IMG]

    You do not need to add println on the last sentence though, notice how I added it in the Hello how are you line, but not in the I am doing fine line? That is because when you use println, it only makes the next print out drop to the next line.

    So if we had:

    It would read:
    Because println was on the second line, instead of the first. It always needs to be above the line you want to drop down.

    Well, I hope this cleared some stuff up for new users to Java. Thank you guys.



    ~~ Diabl0
     
  2. wackywamba

    wackywamba Guru

    Joined:
    Jul 14, 2005
    Posts:
    1,358
    Referrals:
    0
    Sythe Gold:
    1
    Understanding basics of Java - print and println

    Quite a long post to describe a simple concept...

    println() goes to the next line...

    You could state that it's the condensed form of print("\n") or the c++ equivelant of cout << endl
     
< Selling Level 49 Pure, 1100+ Total 93 Magic. | In what forum do I sell runescape pins? >


 
 
Adblock breaks this site