Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Quiz Four Solved for Computer Science 1 | CS 120, Quizzes of Computer Science

Material Type: Quiz; Professor: Lueer; Class: Computer Science 1.; Subject: COMPUTER SCIENCE; University: Ball State University; Term: Fall 2006;

Typology: Quizzes

2009/2010

Uploaded on 03/28/2010

koofers-user-sp6
koofers-user-sp6 🇺🇸

10 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Name:_____________________________
Name:_____________________________
Name:_____________________________
Quiz 4
CS 120-2, Fall 2006
1. Assume that v is a Vector. What does the following program part do? (2 points)
int i = v. size() - 1;
while( i >= 0 ) {
System. out. println( v. get( i ) );
i--;
}
It prints out all the elements of v in inverse order.
2. Write a program part that does the same thing as the one above, but uses an array instead of a Vector.
(2 points)
int i = a. length – 1;
while( i >= 0 ) {
System. out. println( a[ i ] );
i--;
}
3. What does the following program part print out?(1 point)
int[] a = new int[ 4 ] ;
a[ 3 ] = 34;
a[ 2 ] = 12;
a[ 1 ] = 45;
a[ 0 ] = 11;
for( int i: a ) {
System. out. println( i );
}
11
45
12
34

Partial preview of the text

Download Quiz Four Solved for Computer Science 1 | CS 120 and more Quizzes Computer Science in PDF only on Docsity!

Name:_____________________________ Name:_____________________________ Name:_____________________________

Quiz 4

CS 120-2, Fall 2006

  1. Assume that v is a Vector. What does the following program part do? (2 points) int i = v. size() - 1; while( i >= 0 ) { System. out. println( v. get( i ) ); i--; } It prints out all the elements of v in inverse order.
  2. Write a program part that does the same thing as the one above, but uses an array instead of a Vector. (2 points) int i = a. length – 1; while( i >= 0 ) { System. out. println( a[ i ] ); i--; }
  3. What does the following program part print out?(1 point) int[] a = new int[ 4 ] ; a[ 3 ] = 34; a[ 2 ] = 12; a[ 1 ] = 45; a[ 0 ] = 11; for( int i: a ) { System. out. println( i ); } 11 45 12 34