Java Reference
In-Depth Information
4. 2 2
4
Note that
2 + " " + 2
contains a string, namely " " . So, Java knows it is supposed to produce a string.
On the other hand, 2 + 2 contains only integers. So Java thinks + denotes addition
in this second case and produces the value 4 to be output.
5 . START1234567890
STARTJelly beansEND
STARTJelly beansEND
START Jelly beansEND
6. The last two of the following lines end with a blank. The last line begins with two
blanks, one that follows %n in the format string and one because the field width is
9 but the number to be output fills only eight spaces.
START1234567890
STARTJelly beansEND
123.1235
7 . System.out.printf("%15.3e", d);
8 . $1.23
$15.68
9. Either
import java.awt.Robot;
or
import java.awt.*;
10. import java.util.Scanner;
11. Scanner frank = new Scanner(System.in);
12. w = frank.next();
13. import java.util.Scanner;
public class Exercise
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter two numbers.");
int n1 = keyboard.nextInt();
int n2 = keyboard.nextInt();
int sum = n1 + n2;
System.out.println(n1 + " plus " + n2 + " is " + sum);
}
}
Search WWH ::




Custom Search