Scanner Methods Quiz
By Mickey Arnold
starstarstarstarstarstarstarstarstarstar
Last updated 10 months ago
5 Questions
1 point
1
Question 1
1.
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 );
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 );
1 point
1
Question 2
2.
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 );
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 );
1 point
1
Question 3
3.
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 );
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 );
1 point
1
Question 4
4.
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 );
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 );
1 point
1
Question 5
5.
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++;}
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++;
}