What does the following segment of Java code print out?
double x = 4.5; int y = (int) x;
System.out.println(x+" "+y);
4.5 4
A java construct used to store data.
What is a Variable?
What does the following segment of Java code print out?
int x = 7, y = 3;
int z = x/y + x%y;
if (z == x)
y++;
if (z == y)
x++;
System.out.println(x+" "+y+" "+z);
8 3 3
What does the following segment of Java code print out?
for (int i=1; i<30; i = i + 3) {
if (i%2 == 0)
System.out.print((i/2)+" ");
} System.out.println();
2 5 8 11 14
The primary software construct in Java, An encapsulated collection of a class.
What is an Object?
What does the following code segment print out?
for (int i=5; i>0; i--) {
for (int j=0; j<i; j++) {
System.out.print((2*i-j) + " ");
} System.out.println();
}
10 9 8 7 6
8 7 6 5
6 5 4
4 3
2
A common runtime exception that occurs when you try to access an element at an index that is outside the valid range of a data structure
What is an ArrayIndexOutOfBoundsException?
When there are multiple methods with the same name but a different signature in the same class.
What is Overloading?
A method that belongs to a class, but it does not belong to an instance of that class and this method can be called without the instance or object of that class.
What is a Static Method?
What does the following segment of Java code do in general?
Scanner console= new Scanner(System.in); System.out.println("Enter n.");
int n = console.nextInt();
int total = 0;
while (n > 0) {
total = total + n%10;
n = n/10;
} System.out.println(total);
This segment of code prints out the sum of the digits of the original value of n entered by the user.