Java type conversion: Given x and y’s definitions below, what is the value of z
ID: 3707294 • Letter: J
Question
Java type conversion:
Given x and y’s definitions below, what is the value of z in the table below?
int x = 3;
int y = 5;
double z = x / y;
int x = 3;
int y = 5;
double z = (double) x / y;
What is the difference between next() method and nextLine() method in class Scanner? If the user input is “John Doe”, with a space separating the first and last name, what is the result being reading in under these two methods
?
int x = 3;
int y = 5;
double z = x / y;
int x = 3;
int y = 5;
double z = (double) x / y;
Explanation / Answer
1) a) int x = 3; int y = 5; double z = x / y; => value of z is 0 b) int x = 3; int y = 5; double z = (double) x / y; => value of z is 0.6 2) next() only reads until a white space(like space) is read nextLine() reads until a newline character is read for input of "John Doe" next() reads John nextLine() reds John Doe
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.