Expressions
Of course you can do more in using vaiables.
For example: You can write some math formula here like the excerpt below:
Hey, that's the famous E = mc2 formula! You bet! :-) Of course you can do more complex equation with Java. These kind of equations will later be called expressions.
long E;
int m, c;
m = 5;
c = 3000;
E = m * c * c;
Keep in mind that Java doesn't have the ^ operator like BASIC. The power sign for Java will be discussed later.
Oh yes, in case you wonder this line:
System.out.println("Hi, my name is "+name);Well, to print out variables onto the screen, simply put the plus sign after the text quotes you want to display, like the first lane in the above example. In the second line, suppose you want to continue with some more texts, you may add the plus sign, and again put some texts. Don't forget to wrap up the text with double quotes as well. If you just want to print out the variables, then you can do like this:
System.out.println("I am "+age+" years old.");
System.out.println(myvariable);Hmm... pretty simple, eh?
0 comments:
Post a Comment