ICS3U QUIZ-3 Name:
Date:
Total: /45
K/U:
/16
Thinking:
/13
Application:
/11
Communication:
/5
Questions 1-6 are multiple choice questions. Circle your answer. K/1 each
• Which of the following is NOT a numeric data type?
int double
decimal
• A variable that holds a whole number
string boolean
int float
• A variable that holds words
string boolean
int double
• A variable that holds decimal number
string boolean
int double
• Java syntax to create an array of student name with size 15.
• String [ ] name = new String; B. String [ ] name = new String [15];
C. name = new String [15]; D. String [15] name = new String [ ];
• Consider the following declaration: double salary[10]; The array name is:
• double B. salary
C. 10 D. None above
• What will be the final output? K/2
int sum1 = 100 + 50; int sum2 = sum1 + 250;
int sum3 = sum2 + sum2; System.out.println(sum3);
• What will be the output? K/2
int x = 10; x = x + 5;
System.out.println(x);
• What will be the output? K/2
int x = 4;
System.out.println(x < 5 && x < 10);
• What is the output of below code? K/2 int x = 5;
System.out.println(x++); System.out.println(x);
• Consider the following Java statements. What is the resulting value of each variable?
T/6
A: int x, y;
x = 1;
y = 2;
y = x;
x = y++;
B. int x, y, z; x = 1;
y = 2;
z = y; y = --x;
x = z--;
C. int z, y; z = 2;
z = z + 1; y =++z;
Value of x: Value of y:
Value of x: Value of y:
Value of x: Value of y:
• What must the test be so that the following code prints out the integers 5 through and including 15?
for ( int j = 5; ; j++ ) A/2
{
System.out.print( j + " " );
}
• What must the change be so that the following fragment prints out the even integers 0 2 4 6 8 10?
A/2
for ( int j = 0; j <= 10; )
{ System.out.print( j + " " );
}
• What must the initialization be so that the following fragment prints out the integers
-3 -2 -1 ?
for ( ; j < 0; j++ ) A/2
{
System.out.print( j + " " )
}
• What is the output of the following code? T/2, C1 int x = 0;
while (x < 4) { x = x + 1;
}
System.out.println("x is " + x);
• What is the output of the following code fragment: A/2, C1 int[] ar = {2, 4, 6, 8 };
System.out.println(ar[0] + " " + ar[3] );
• What is the output of the following code fragment? T/2, C1 for ( int j = 10; j > 5; j– )
{
System.out.print( j + ” ” );
}
• What is the length of the following array: int [ ] data = { 12, 34, 9, 0, -62, 88 }; K/1
• What is the index of the element “4” in the array “array1” given the following declaration:
int[] array1 = {2, 5, 7, 4, 6, 8 }
K/1
• What is the output for y? T/3, C1
int y = 0;
for (int i = 0; i<5; i++) { y =y+ i;
}
System.out.println(y);
• What does the following code do? A/3, C1 public static void main(String[] args)
{
int[] my_array = {25, 14, 56, 15, 36, 56, 77, 18, 29, 49};
int[] new_array = new int[10];
for(int i=0; i < my_array.length; i++)
{
new_array[i] = my_array[i];
}