Tracing Array of Integers Practice Quiz

If you’re preparing for the Computer Science AP-A Exam, you’ll want to be very good with arrays. Here’s a small little quiz to get you some practice.


What is output by the following Java code?

int[] nums = {29, 7, 56, 19, 26, 22, 54, 53};
int s = 0; 
for (int i=1; i<nums.length; i++) {
  if (nums[i] < s) {
    s = nums[i]; 
  }
}
System.out.println(s); 
 
 
 
 
 

What is output by the following Java code?

int[] a = {29, 7, 56, 19, 26, 22, 54, 53};
int[] b = {1, 7, 5, 3, 4, 2, 0, 6};

int s = 0; 
for (int i=1; i<b.length; i+=2) {
  s += a[b[i]];
}
System.out.println(s); 
 
 
 
 
 

What is output by the following code?

int[] nums = {1, 4, 3, 2, 7, 8};
int s = -5; 
for (int i=1; i<nums.length; i+=2) {
  s += nums[i];
}
System.out.println(s); 
 
 
 
 
 

What is output by the following Java code?

int[] nums = {29, 7, 56, 19, 26, 22, 54, 53};
int s = 0; 
for (int i=1; i<nums.length; i++) {
  if (nums[i] > s) {
    s = nums[i]; 
  }
}
System.out.println(s);
 
 
 
 
 

What is the output from the following Java code?

int[] a = {29, 7, 56, 19, 26, 22, 54, 53};

int s = 0; 
for (int i=a.length - 1; i>0; i--) {
  s += a[i];
}
System.out.println(s); 
 
 
 
 
 

Question 1 of 5

Why ClassCube?

Are you spending too much time grading your students' source code?

ClassCube is an online tool for Computer Science teachers that allows you to create lab assignments for your students. They'll submit their code online and ClassCube will automatically grade it for you.

Teaching with ClassCube…

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>