Computer Science 1st Semester Final Exam

Is this your test? Login to manage it. If not, you can develop an exam just like it.

This is a non-interactive preview of the quiz content.

1.
2 points
What is the output by the code below?

double y = 4.0;
int x = y;
System.out.println(x);
2.
2 points
What is output by the code below?

Scanner s = new Scanner("1 2 3 4 5 6");
int x = 0;
double z = 0;
while(s.hasNext())
{
x += s.nextInt();
z++;
}
System.out.println( x / z );
3.
2 points
What is the output by the code below?

int cost = 3.8;
System.out.println("Price: " + cost);
4.
2 points
In Java, every program statement ends with a what ?
5.
2 points
What is output by the code below?

int[] array = {5,7,8,11,4};
for(int i=0; i{
array[i]=array[array.length-i-1];
}
System.out.println(array[0]);
6.
2 points
What is the output by the code below using the following data file?

nums.dat
2
5
7

Scanner file = new Scanner(new File("nums.dat"));
file.nextInt();
System.out.println(file.nextInt()+" "+file.nextInt());
7.
2 points
What is the output by the code below using the following data file?

nums.dat
2
5
7

Scanner file = new Scanner(new File("nums.dat"));
System.out.println(file.nextInt()+" "+file.nextInt());
8.
2 points
What is the output by the code below?

String s = "aplus";
System.out.println("" + s);
9.
2 points
What is output by the code below?

int[] array = {5,7,8,11,4};
int sum = 0;
for(int i = 0; i sum = sum + array[i];
System.out.println(sum);
10.
2 points
What is the output by the code below using the following data file?

nums.dat
2
5
7

Scanner file = new Scanner(new File("nums.dat"));
System.out.println(file.nextInt());
11.
2 points
Which of the following lines correctly defines a double variable?
12.
2 points
Given the following statement, var must be defined as which of the following types?

var = keyboard.nextByte();
13.
2 points
What is output by the code below?

int[] array = {5,7,8,11,4};
out.println(array[array.length-1]);
14.
2 points
Which of the following Scanner methods can be used to read in the value go back ?
15.
2 points
What is the output by the code below?

System.out.println("Hello ");
System.out.print("people ");
16.
2 points
What is output by the code below?

int[] nums = new int[10];
for (int i=0; i < nums.length; i++)
{
nums[i] = i*2;
}
System.out.println(nums[5]);
17.
2 points
Given the following statement, var must be defined as which of the following types?

var=keyboard.nextInt();
18.
2 points
Every method must have an open and close what?
19.
2 points
What is output by the code below?

Scanner s = new Scanner("1 2 3 4 5 6");
int x = 0;
x += s.nextInt();
x += s.nextInt();
System.out.println( x );
20.
2 points
Which of the following data types uses 64 bits of memory?
21.
2 points
What is output by the code below?

int[] array = {5,7,8,11,4};
out.println(array[7/2]);
22.
2 points
Given the following statement, var must be defined as which of the following types?

var = keyboard.next();
23.
2 points
Which of the following Scanner methods can be used to read in the value 64532 ?
24.
2 points
Which of the following Scanner methods can be used to read in the value 31980 ?
25.
2 points
What is the output by the code below?

System.out.println( 3 + 3 );
26.
2 points
What is output by the following code?

System.out.println(7 + "" + 5);
27.
2 points
What is the output by the code below?

System.out.println( 3 + "\t" + 3 );
28.
2 points
What is output by the code below?

Scanner s = new Scanner("1 2 3 4 5 6");
int x = 0;
x += s.nextInt();
x += s.nextInt();
x += s.nextInt();
x += s.nextInt();
System.out.println( x );
29.
2 points
Which of the following lines correctly defines an integer variable?
30.
2 points
What is output by the code below?

int[] array = {5,7,8,11,4};
out.println( array[0] );
31.
2 points
What is output by the code below?

int[] array = {5,7,8,11,4};
out.println(array.length);
32.
2 points
Which of the following Scanner methods can be used to read in the value 92 ?
33.
2 points
What is the output by the code below?

int x = 4;
double y = x;
System.out.println(y);
34.
2 points
What is output by the code below?

int[] array = {5,7,8,11,4};
out.println( array[1] );
35.
2 points
Given the following statement, var must be defined as which of the following types?

var = keyboard.nextLine();
36.
2 points
What is the output by the code below?

System.out.println( "\"99" );
37.
2 points
What is output by the code below?

Scanner s = new Scanner("d 1 o 2 g 3 c 7 t");
int count = 0;
while(s.hasNext())
{
if (count % 2 == 1)
System.out.print(s.next() + " ");
else
s.next();
count++;
}
38.
2 points
Which of the following lines correctly defines a String variable?
39.
2 points
What is the output by the code below using the following data file?

nums.dat
3
2
5
7

Scanner file = new Scanner(new File("nums.dat"));
int size = file.nextInt();
int x = 0;
for(int i=1; i <= size; i++)
{
int num = file.nextInt();
x = x + num;
}
out.print( x + " ");
40.
2 points
What is the output by the code below using the following data file?

nums.dat
3
2
5
7

Scanner file = new Scanner(new File("nums.dat"));
int size = file.nextInt();
for(int i=1; i <= size; i++)
{
int num = file.nextInt();
out.print( num + " ");
}
41.
2 points
Which of the following is the newline character?
42.
2 points
What is output by the code below?

Scanner s = new Scanner("1 2 3 4 5 6");
int x = 0;
while(s.hasNext())
{
x += s.nextInt();
}
System.out.println( x );
43.
2 points
What is the output by the code below?

double num = 7.5;
System.out.println("Number: " + num);
44.
2 points
What is the output by the code below?

System.out.print("ac" );
45.
2 points
What is output by the code below?

int[] array = {5,7,8,11,4};
out.println( array[5/2] );
46.
2 points
Given the following statement, var must be defined as which of the following types?

var = keyboard.nextDouble();
47.
2 points
What is output by the code below?

int[] array = {5,7,8,11,4};
out.println(array[array.length]);
48.
2 points
Which of the following data types uses 32 bits of memory?
49.
2 points
What is the output by the code below?

System.out.print("ab\\\\ab" );
50.
2 points
Which of the following Scanner methods can be used to read in the value 11.25 ?