Looks like no one added any tags here yet for you.
Assuming that scan is a properly initialized Scanner variable, which of the following correctly inputs a String?
String val = scan.nextLine();
Consider the following code:
int x = -3;
x--;
System.out.println(x);
What is output?
-4
Which of the following data types would be most appropriate to use when recording whether a switch is in the "on" or "off" position?
boolean
Which of the following is NOT a primitive data type?
String
What is output by the following code?
int a = 91;
System.out.println(a / 2);
45
Which of the following is a legal variable name in Java?
ans
What is (6 % 2) * 7?
0
Which of the following would properly create A and B as integer variables?
int A;
int B;
Which of the following correctly stores the word umbrella in a variable called stuff?
String stuff = "umbrella";
Consider the following code:
int c = 3 - 37 % 2;
System.out.println(c);
What is output?
2
Consider the following code:
int x = 9;
int y = 6;
System.out.println( (x*y)/x );
What is output?
6
Consider the following variable declaration:
double y = 52;
Does a cast need to be added so this code will compile and run successfully? ______. If so, what should be typed for this cast? _______
no, nothing
For which of the following would modular division be LEAST likely to be useful?
converting decimals to whole numbers
The following code is intended to input three integers and print the average. What is a potential problem with the code as written?
System.out.println("Please enter three integers: ");
int a = scan.nextInt();
int b = scan.nextInt();
int c = scan.nextInt();
System.out.println("The average is: " + (a + b + c) / 3);
It needs a cast so that the decimal portion will be shown.
What is output by the following code?
int val = -2;
val++;
val--;
val++;
val++;
val++;
val--;
val++;
System.out.println(val);
1
What is the value of w after executing this segment of code?
int w = 18;
w += 18;
36
When might you encounter a problem with integer overflow?
When trying to store an integer which is too big to be stored in an int variable
There are two integer variables in our program, minutes and hours, which represents time. If in the program, we increase the number of minutes by one, which of the following lines of code will correctly update hour and minutes?
hours = hours + minutes / 60;
minutes = minutes % 60;
Correct the following code so that q stores the nearest integer below 82.3847.
int q = 82.3847;
int q = (int) 82.3847;
Which of the following will print the ones column of an integer stored in x?
System.out.print(x % 10);