02slide Accessible
02slide Accessible
Data Structures
Thirteenth Edition
Chapter 2
Elementary Programming
2.9 To read a byte, short, int, long, float, or double value from the
keyboard (§2.9.1).
ComputeAreaWithConsoleInput ComputeAverage
No performance difference
long negative 2 to the power 63 to 2 to the power 63 minus 1 left parenthesis that is,
263 to9223372036854775808
negative 263 1 to 9223372036854775807 right parenthesis.
64-bit signed
i.e., 9223372036854775808 to 9223372036854775807
float Negative range: 32-bit IEEE 754
negative range, negative -3.4028235 E + 38 to negative 1.4 E minus 45, positive range, 1.4 E minus 45 to 3.4028235 E + 38.
3.4028235E 38 to 1.4E 45
Positive range:
1.4E 45 to 3.4028235E 38
Negative range:
1.7976931348623157E 308 to 4.9E 324
Positive range:
4.9E 324 to 1.7976931348623157E 308
Method Description
nextByte() reads an integer of the byte type.
nextShort() reads an integer of the short type.
nextInt() reads an integer of the int type.
nextLong() reads an integer of the long type.
nextFloat() reads a number of the float type.
nextDouble() reads a number of the double type.
+ Addition 34 + 1 35
The symbol of minus
Subtraction 34.0 0.1
34.0 minus 0.1
33.9
* Multiplication 300 * 30
300 times 30
9000
/ 1.0 / 2.0
division slash
%
symbol of modulo remainder
Remainder 2
20 modulo remainder 3
20 % 3
DisplayTime
System.out.println(1.0 − 0.9);
The double type values are more accurate than the float
type values. For example,
System.out.println("1.0 / 3.0 is " + 1.0 /
3.0);
3 4 x 10 y 5 a b c 4 9x
9( )
5 x x y
is translated to
3 4 * x / 5 10 * y 5 * a b c / x 9 * 4 / x 9 x / y
5
celsius fahrenheit 32
9
Note: you have to write
celsius 5.0 / 9 * fahrenheit 32
FahrenheitToCelsius
ShowCurrentTime
negative = Subtraction assignment i 8
i minus = 8 i i 8 I = I minus 8
/
forward slash = Division assignment i / 8
I forward slash = 8
i i / 8
I = I over 8
++variable;
variable++;
variable;
variable ;
byte i = 100;
long k = i * 3 + 4;
double d = i * 3.1 + k / 2;
SalesTax
loanAmount monthlyInterestRate
monthlyPayment
1
1
1 monthlyInterestRate
numberOfYears 12
ComputeLoan
ComputeChange