Java Reference
In-Depth Information
The code is not wrong, but inefficient. It creates two input objects unnecessarily and may
lead to some subtle errors. You should rewrite the code as follows:
Scanner input = new Scanner(System.in);
System.out.print( "Enter an integer: " );
int v1 = input.nextInt();
System.out.print( "Enter a double value: " );
double v2 = input.nextDouble();
GOOD CODE
2.34
Can you declare a variable as int and later redeclare it as double ?
Check
2.35
What is an integer overflow? Can floating-point operations cause overflow?
Point
2.36
Will overflow cause a runtime error?
2.37
What is a round-off error? Can integer operations cause round-off errors? Can
floating-point operations cause round-off errors?
K EY T ERMS
algorithm 34
assignment operator ( = )42
assignment statement 42
byte type 45
casting 57
constant 43
data type 35
declare variables 35
decrement operator ( -- )55
double type 45
expression 42
final keyword 43
float type 45
floating-point number 35
identifier 39
increment operator ( ++ )55
incremental code and testing 62
int type 45
IPO 39
literal 48
long type 45
narrowing (of types) 57
operands 46
operator 46
overflow 65
postdecrement 55
postincrement 55
predecrement 55
preincrement 55
primitive data type 35
pseudocode 34
requirements specification 59
scope of a variable 41
short type 45
specific import 38
system analysis 59
system design 59
underflow 66
UNIX epoch 52
variable 35
widening (of types) 57
wildcard import 00
C HAPTER S UMMARY
1.
Identifiers are names for naming elements such as variables, constants, methods, classes,
packages in a program.
2.
An identifier is a sequence of characters that consists of letters, digits, underscores ( _ ),
and dollar signs ( $ ). An identifier must start with a letter or an underscore. It cannot start
with a digit. An identifier cannot be a reserved word. An identifier can be of any length.
3. Variables are used to store data in a program. To declare a variable is to tell the compiler
what type of data a variable can hold.
 
 
Search WWH ::




Custom Search