Chapters 1 2 3
Expressions & Statements

  1. Write the print “Hello World!” program.

  2. Write a program to read feet as a single real number, print it, and convert and print the equivalent value in meters.

Input: 57.6
Output: 17.55648

  1. Write a program to use a single printf to output 34 67.9 true "hello".

5. Now improve program 4 by reading the three values from Scanner input.
6. Write a program to read blank or new-line separated integers until the sentinel value 9999 is read, print the integers as they are read on separate lines, and finally their sum.

Input: 1 2 3 4 5 6 7 8 9 9999
Output:
1
2
3
4
5
6
7
8
9
The sum is 45
7. Repeat the program with the input integers but do not sum even integers.
Input: 1 2 3 4 5 6 7 8 9 9999
Output:
1
2
3
4
5
6
7
8
9
The sum is
25
8. Repeat the program with the input integers
but do not sum the integers 4 5 11 13 17. You must use a switch statement.
Input: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 9999
Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
The sum is 160
9. Write a program that reads an integer N and then prints a right-triangle consisting of N lines of [].
Input: 3
Output:
[]
[][]
[][][]
10. Write a program to read two blank or new-line separated BigIntegers, print them, and then multiply them, and print the result. (import java.math.BigInteger). Note Scanner reads BigIntegers with the method nextBigInteger().
Input: 12448586683 38585868686
Output: 480339531076526308538
11. Write a program to read two Booleans a and b. Calculate (a or b) ^ !(a and b) and print a, b, and the result.
Input: false true
Output:
false true false
Input: false false
Output:
false false true