Files Unit Test
By Mickey Arnold
starstarstarstarstarstarstarstarstarstar
Last updated 10 months ago
23 Questions
1 point
1
Question 1
1.
What is output by the code below?
Scanner s = new Scanner("aplus comp sci 212");System.out.println( s.next() );
What is output by the code below?
Scanner s = new Scanner("aplus comp sci 212");
System.out.println( s.next() );
1 point
1
Question 2
2.
What is output by the code below?Scanner s = new Scanner("aplus comp sci 212");s.next();System.out.println( s.next() );
What is output by the code below?
Scanner s = new Scanner("aplus comp sci 212");
s.next();
System.out.println( s.next() );
1 point
1
Question 3
3.
What is output by the code below?Scanner s = new Scanner("aplus comp sci 212");s.next();s.next();System.out.println( s.next() );
What is output by the code below?
Scanner s = new Scanner("aplus comp sci 212");
s.next();
s.next();
System.out.println( s.next() );
1 point
1
Question 4
4.
What is output by the code below?Scanner s = new Scanner("aplus comp sci 212");s.next();s.next();s.next();System.out.println( s.next() );
What is output by the code below?
Scanner s = new Scanner("aplus comp sci 212");
s.next();
s.next();
s.next();
System.out.println( s.next() );
1 point
1
Question 5
5.
What is output by the code below?Scanner s = new Scanner("aplus comp sci 212");s.next();s.next();s.next();s.next();System.out.println( s.next() );
What is output by the code below?
Scanner s = new Scanner("aplus comp sci 212");
s.next();
s.next();
s.next();
s.next();
System.out.println( s.next() );
1 point
1
Question 6
6.
What is output by the code below?Scanner s = new Scanner("1337 888 212 91");s.next();s.next();System.out.println( s.nextInt() );
What is output by the code below?
Scanner s = new Scanner("1337 888 212 91");
s.next();
s.next();
System.out.println( s.nextInt() );
1 point
1
Question 7
7.
What is output by the code below?Scanner s = new Scanner("13 8 25 9");System.out.println( s.nextInt() + s.nextInt() );
What is output by the code below?
Scanner s = new Scanner("13 8 25 9");
System.out.println( s.nextInt() + s.nextInt() );
1 point
1
Question 8
8.
What is output by the code below?Scanner s = new Scanner("aplus comp sci 212");System.out.println( s.nextInt() );
What is output by the code below?
Scanner s = new Scanner("aplus comp sci 212");
System.out.println( s.nextInt() );
1 point
1
Question 9
9.
What is output by the code below?Scanner s = new Scanner("aplus comp sci 212");s.next();s.next();s.next();System.out.println( s.nextInt() );
What is output by the code below?
Scanner s = new Scanner("aplus comp sci 212");
s.next();
s.next();
s.next();
System.out.println( s.nextInt() );
1 point
1
Question 10
10.
What is output by the code below?Scanner s = new Scanner("aplus comp sci 212");s.next();s.next();s.next();System.out.println( s.nextInt() * 2 );
What is output by the code below?
Scanner s = new Scanner("aplus comp sci 212");
s.next();
s.next();
s.next();
System.out.println( s.nextInt() * 2 );
1 point
1
Question 11
11.
What is output by the code below?Scanner s = new Scanner("15 20.5 99 11.5");System.out.println( s.nextInt() );
What is output by the code below?
Scanner s = new Scanner("15 20.5 99 11.5");
System.out.println( s.nextInt() );
1 point
1
Question 12
12.
What is output by the code below?Scanner s = new Scanner("15 20.5 99 11.5");s.nextInt();System.out.println( s.nextInt() );
What is output by the code below?
Scanner s = new Scanner("15 20.5 99 11.5");
s.nextInt();
System.out.println( s.nextInt() );
1 point
1
Question 13
13.
What is output by the code below?Scanner s = new Scanner("15 20.5 99 11.5");s.nextInt();System.out.println( s.nextDouble() );
What is output by the code below?
Scanner s = new Scanner("15 20.5 99 11.5");
s.nextInt();
System.out.println( s.nextDouble() );
1 point
1
Question 14
14.
Consider the code that follows.Scanner scan = new Scanner("4 3 2 5 1");int sum = 0;while(scan.hasNextInt()){ /* code */}Which of the following are valid statements?I.System.out.println(scan.next());II.sum += scan.next();III.System.out.println(scan.nextInt());
Consider the code that follows.
Scanner scan = new Scanner("4 3 2 5 1");
int sum = 0;
while(scan.hasNextInt())
{
/* code */
}
Which of the following are valid statements?
I.
System.out.println(scan.next());
II.
sum += scan.next();
III.
System.out.println(scan.nextInt());
1 point
1
Question 15
15.
Consider the code that follows.Scanner scan = new Scanner("4.7 3 2.4 5 1");double sum = 0;while( scan.hasNextDouble() ){ /* code */}Which of the following are valid statements?I.sum += scan.next();II.sum += scan.nextDouble();III.System.out.println(scan.nextInt());
Consider the code that follows.
Scanner scan = new Scanner("4.7 3 2.4 5 1");
double sum = 0;
while( scan.hasNextDouble() )
{
/* code */
}
Which of the following are valid statements?
I.
sum += scan.next();
II.
sum += scan.nextDouble();
III.
System.out.println(scan.nextInt());
1 point
1
Question 16
16.
Consider the code that follows.Scanner scan = new Scanner("4.7 it at 2.4 5 1");String sum = "";while( scan.hasNext() ){ /* code */}Which of the following are valid statements?I.sum += scan.next();II.sum += scan.nextInt();III.sum += scan.nextDouble();
Consider the code that follows.
Scanner scan = new Scanner("4.7 it at 2.4 5 1");
String sum = "";
while( scan.hasNext() )
{
/* code */
}
Which of the following are valid statements?
I.
sum += scan.next();
II.
sum += scan.nextInt();
III.
sum += scan.nextDouble();
1 point
1
Question 17
17.
What is output by the code below?Scanner s = new Scanner("a 2 f q 7e 8 r 2 a");int count = 0;while(s.hasNext()){ if (count % 3 == 1) out.print(s.next() + " "); else s.next(); count++;}
What is output by the code below?
Scanner s = new Scanner("a 2 f q 7e 8 r 2 a");
int count = 0;
while(s.hasNext())
{
if (count % 3 == 1)
out.print(s.next() + " ");
else
s.next();
count++;
}
1 point
1
Question 18
18.
What is output by the code below?Scanner s = new Scanner("a 2 f q 7e 8 r 2 a");int count = 0;while(s.hasNext()){ if (count % 3 == 1) out.print(s.next() + " "); count++;}
What is output by the code below?
Scanner s = new Scanner("a 2 f q 7e 8 r 2 a");
int count = 0;
while(s.hasNext())
{
if (count % 3 == 1)
out.print(s.next() + " ");
count++;
}
1 point
1
Question 19
19.
What is output by the code below?Scanner s = new Scanner("a 2 f q 7e 8 r 2 a");int count = 0;while(s.hasNext()){ if (count % 3 == 1) count++; s.next();}System.out.println(count);
What is output by the code below?
Scanner s = new Scanner("a 2 f q 7e 8 r 2 a");
int count = 0;
while(s.hasNext())
{
if (count % 3 == 1)
count++;
s.next();
}
System.out.println(count);
1 point
1
Question 20
20.
What is the output by the code below using the following data file?nums.dat34231122
Scanner file = new Scanner(new File("nums.dat"));System.out.println(file.nextInt()+" "+file.nextLine());
What is the output by the code below using the following data file?
nums.dat
34
23
11
22
Scanner file = new Scanner(new File("nums.dat"));
System.out.println(file.nextInt()+" "+file.nextLine());
1 point
1
Question 21
21.
What is the output by the code below using the following data file?nums.dat34231122
Scanner file = new Scanner(new File("nums.dat"));System.out.println(file.nextInt()+" "+file.next());
What is the output by the code below using the following data file?
nums.dat
34
23
11
22
Scanner file = new Scanner(new File("nums.dat"));
System.out.println(file.nextInt()+" "+file.next());
1 point
1
Question 22
22.
What is the output by the code below using the following data file?nums.dat334231122
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 + " ");}
What is the output by the code below using the following data file?
nums.dat
3
34
23
11
22
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 + " ");
}
1 point
1
Question 23
23.
What is the output by the code below using the following data file?nums.dat534231122
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 + " ");}
What is the output by the code below using the following data file?
nums.dat
5
34
23
11
22
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 + " ");
}