1/49
JAVA PROGRAMMING
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
24 % 5 is ________
4
What is y displayed in the following code?
public class Test {
public static void main(String[] args) {
int x = 1;
int y = x++ + x;
System.out.println("y is " + y);
}
}
y is 3
Which of the following is a valid identifier? Please select all that apply.
radius & $343
According to Java naming convention, which of the following names can be variables? Please select all that apply.
findArea & totalLength
To assign a double variable d to a float variable x, you write ________.
x = (float)d;
Are the following four statements equivalent?
number += 1;
number = number + 1;
number++;
++number;
Yes
Which of the following expression results in 45.37?
(int)(45.378 * 100) / 100.0
What is x after the following statements?
int x = 2;
int y = 1;
x *= y + 1;
x is 4
To add number to sum, you write ________. (Note: Java is case-sensitive) Please select all that apply.
sum += number;
Suppose x is 1. What is x after x -= 1?
0
25 % 1 is ________
0
If you attempt to add an int, a byte, a long, and a double, the result will be a(n) ________ value.
double
The expression (int)(76.0252175 * 100) / 100 evaluates to ________.
76
-25 % 5 is ________
0
Which of the following are correct names for variables according to Java naming conventions? Please select all that apply.
radius & findArea
Which of the following assignment statements is incorrect? Please select all that apply.
i = 1 = j = 1 = k = 1;
i == j == k == 1;
Which of the following is incorrect?
float x = 1.0;
Suppose x is 1. What is x after x += 2?
3
To declare a constant MAX_LENGTH inside a method with value 99.98, you write ________.
final double MAX_LENGTH = 99.98;
What is the value of (double)5/2?
2.5
The System.currentTimeMillis() returns ________.
the current time in milliseconds since midnight, January 1, 1970 GMT (the Unix time)
Suppose a Scanner object is created as follows, what method do you use to read a real number?
Scanner input = new Scanner(System.in);
input.nextDouble();
What is the output of the following code?
double x = 5.5;
int y = (int)x;
System.out.println("x is " + x + " and y is " + y);
x is 5.5 and y is 5
Which of the following is a constant, according to Java naming conventions? Please select all that apply.
COUNT
MAX_VALUE
The expression 4 + 20 / (3 - 1) * 2 is evaluated to ________.
24
Which of these data types requires the most amount of memory?
long
-24 % 5 is ________
-4
Which of the following expression results in a value 1?
37 % 6
Which of the following expressions will yield 0.5? Please select all that apply.
1.0 / 2
1 / 2.0
(double) 1 / 2
What is y displayed?
public class Test {
public static void main(String[] args) {
int x = 1;
int y = x + x++;
System.out.println("y is " + y);
}
}
y is 2
If you enter 1 2 3, when you run this program, what will be the output?
import java.util.Scanner;
public class Test1 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter three numbers: ");
double number1 = input.nextDouble();
double number2 = input.nextDouble();
double number3 = input.nextDouble();
// Compute average
double average = (number1 + number2 + number3) / 3;
// Display result
System.out.println(average);
}
}
2.0
What is the value of (double)(5/2)?
2.0
What is the exact output of the following code?
double area = 3.5;
System.out.print("area");
System.out.print(area);
area3.5
The following code fragment reads in two numbers. What is the incorrect way to enter these two numbers?
Scanner input = new Scanner(System.in);
int i = input.nextInt();
double d = input.nextDouble();
Enter a numeric value with a decimal point, a space, an integer, and then the Enter key.
How do you write 2.5 ^ 3.1 in Java?
Math.pow(2.5, 3.1)
________ is the Java assignment operator.
=
To improve readability and maintainability, you should declare a ________ for PI instead of using literal values such as 3.14159.
constant
Which of the following are correct ways to declare variables? Please select all that apply.
int length, width;
int length; int width;
-24 % -5 is ________
-4
True or False? Every letter in a Java keyword is in lowercase.
True
To assign a value 1 to variable x, you write ________.
x = 1;
________ is the code with natural language mixed with Java code.
Pseudocode
To add a value 1 to variable x, you write ________. Please select all that apply.
x = x + 1;
x = 1 + x;
x += 1;
What is i printed?
public class Test {
public static void main(String[] args) {
int j = 0;
int i = ++j + j * 5;
System.out.println("What is i? " + i);
}
}
6
What is i printed in the following code?
public class Test {
public static void main(String[] args) {
int j = 0;
int i = j++ + j * 5;
System.out.println("What is i? " + i);
}
}
5
What is the result of 45 / 4?
11
What is x after the following statements?
int x = 1;
x *= x + 1;
x is 2
Which of the following statements are the same?
(A) x -= x + 4
(B) x = x + 4 - x
(C) x = x - (x + 4)
(A) and (C) are the same.
To obtain the current second, use ________.
System.currentTimeMillis() / 1000 % 60
Which of the following assignment statements is illegal?
int t = 4.5;