Exercises 1
Many of the exercises are borrowed from Rich Pattis from Carnegie Mellon University. Many thanks to Rich for letting me use these.
Classify each of the following as a legal or illegal identifier. If it is illegal, propose a legal identifier that can take its place (a homophone or homoglyph)
| packAge | x12 | 2Lips |
| xOrY | sum of squares | %Raise |
| termInAte | u235 | $Bill |
| x_1 |
Classify each of the following numeric literals as int, or double, or illegal (neither); write the equivalent value of each double without using E notation; for each illegal literal, write a legal one with the "same" value.
| 5. | 3.1415 | 17 |
| 17.0 | 1E3 | 1.E3 |
| .5E-3 | 5.4x103 | 50E-1 |
| 1,024
|
0.087
|
.087
|
What is the difference between 5, 5., five,
'5', and "5"? What is the difference between true
and "true"?
Choose an appropriate type to represent each of the following pieces of information
7/10 7./10 7/10. 7./10.
7/10 57/10 157/10 2157/10
7%10 57%10 157%10 2157%10
false == false 'a' < 'Z' 'a'-'A'
true != true true && false true || false
x++ ++x 1 = x
x = 1 x == 1 x = 'A'
Math.abs(-3.5) Math.abs(3.5) Math.max(3.5, 8)
Math.sqrt(-1.) Math.pow(-3.,2.) Math.pow(-3.,.5)
s = System.out.println("Hi");
attendance/capacity
100*attendance/capacity
100*(attendance/capacity)
attendance/capacity*100