Java Reference
In-Depth Information
￿ String s
Declares the variable s of type String.
￿ s = "abc"
Assigns the value "abc" to the variable s .
￿ d = Math.random()
Assigns a random number between 0(inclusive) and 1(exclu-
sive) to the variable d .
Returns a positive integer if s1 > s2 ,0if s1 = s2 ,anda
negative integer if s1<s2 (the string order is lexicographical).
￿
s1.compareTo(s2)
Returns true when the strings are the same and false otherwise.
￿
s1.equals(s2)
￿
if(a > b)
{
...
}⇒
If a>b , then the block is executed.
{
...
}
{
...
}⇒
￿
if(a > b)
If a>b , then only the first block is executed. Oth-
erwise, only the second block is executed.
else
True when a = b .
￿
a==b
￿ a!=b
True when a
= b .
￿ a>=b
True when a b .
￿ a<=b
True when a b .
￿ a>b && c>d
True when a>b and c>d .
￿ a>b || c>d
True when a>b or c>d .
￿ !(a==b)
True when the variables a and b are different.
￿ switch(i) { case 4: ... break; case 5: ... break; ... default: ...
If
i=4 , then the statements for the first case are executed. If i=5 , then the statements
for the second case are executed. If i isnotequaltoanyofthecasevalues,thenthe
statements for the default case are executed.
}⇒
Prints hello followed by a new line.
￿
System.out.println("hello")
￿
System.out.print("hello
\
n")
Prints hello followed by a new line.
￿
System.out.print("hello")
Prints hello .
￿
Scanner keyboard = new Scanner(System.in)
Creates a scanner object.
￿ int i = keyboard.nextInt()
Reads the next integer from the keyboard into the
variable i .
￿ double d = keyboard.nextDouble()
Reads the next double from the keyboard
into the variable d .
￿ String s = keyboard.next()
Reads the next string from the keyboard into the
variable s .
￿ String s = keyboard.nextLine()
Reads the next line from the keyboard into
the variable s .
￿ x = (a>b) ? y : z
If a>b ,then x becomes equal to y . Otherwise, x becomes
equals to z .
 
Search WWH ::




Custom Search