Prepare for tomorrow's quiz by answering the following questions.
(1) Explain the difference between double and int variables.
(2) Predict the result of each operation:
(a)
8 / 2 (b)
9 / 2 (c) Math.sqrt(25) (d)
9.0 / 2.0
(e) 9e3
/ 9e2 (f) 3 / (2 + 1)
(g) 3 / (3 - 3)
(3) Explain the difference between println("hi") ; and print("hi");
(4) Explain why each of the following causes a compile error:
(a) System.out.println(My name is Carl) ;
(b) int x = 4.5 ;
(c) System.out.println("5 EU = " + 5 * 1.25 " dollars");
(d) double num = 25 / (2*2 + 1 ;
(e) int decimal = 3*4 / (5-6)
(f) System.Out.Println("\u0123");
(5) Predict what will be printed by the following :
double x = 1;
for (int c = 0 ; c < 5 ; c++)
{
System.out.println(x);
x = x * 2;
}
(6) State approximately the maximum value that can be stored in an int variable.
Answer true or false:
(7) You can assign a decimal value to an int variable.
(8) You
can assign an integer value to a double variable.
(9) Computers always
do arithmetic calculations correctly.
(10) A String can contain letters
and numbers.
(11) You may use any file-name you like for saving a
Java program.
(12) Numbers are stored inside the computer using binary.
(13)
An int variable cannot store negative numbers.
(14) It is possible
to print a String and a number on the same line,
by
placing a + sign between them.
(15) Math.sqrt(9) produces the answer 81.
Complete this program that changes US dollars to Euros.
Write the entire
program on paper - do not use a computer.
When finished, the program
prints: 10.0 dollars = 8.2 EU
public ________ Money
{
public static void main(String[] args)
{
________ dollars = 10.00 ;
________ euros = _________ * 0.82;
System.________.______( _____ + " dollars = " ________" EU");
}
}