Primitive types
Literal | Discriminator | Type | Value |
---|---|---|---|
29 |
base 10 |
Decimal | 2×101+9×100 |
0b11101 | 0b, base 2 | Binary |
1×24+1×23+1×22 +0×21+1×20 |
0x1D | 0x, base 16 | Hexadecimal | 1×161+13×160 |
035 | 0, base 8 | Octal | 3×81+5×80 |
Name | Bytes | Type | Range | Literal samples |
---|---|---|---|---|
char |
2 / 16 bit | Unsigned integer | [0,216-1] | 'A', '*', '-', 'Ç', '⇶' ... |
float |
4 | Floating point | ±1.18×10-38 to ±3.4×1038 | 3.14f, 0.022f, -3.4E-24f |
double |
8 | Floating point | ±2.23×10-308 to ±1.8×10308 | 3.14, 0.022, -3.4E-24, 3.14d,... |
boolean |
? | Logical value | not applicable | true ,
false |
No. 6
Literal samples
Q: |
Create code printing an example for each type of literal in Java. TipYou may follow Java Literals. |
A: |
No. 7
Literals of type int
Q: |
Calculate the above sample values in decimal beforehand. Then write and execute code printing the above values. |
||||||||||||||||||||
A: |
No. 8
Integer overflow
Q: |
Execute the following code:
Whats wrong here? How can we achieve the desired output? Tip
|
A: |
No. 9
Strange sum result
Q: |
Execute the following code:
Explain the result. TipConsider the |
A: |
No. 10
Correcting the error
Q: |
How do we correct the erroneous outcome in Strange sum result ? TipConsider related Java™ literals. |
A: |