Log in
Sign up for FREE
arrow_back
Library
Scanner Methods Quiz
By Mickey Arnold
star
star
star
star
star
Share
share
Last updated almost 2 years ago
5 questions
Add this activity
1
Question 1
1.
1
Question 2
2.
1
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();
x += s.nextInt();
x += s.nextInt();
System.out.println( x );
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 );
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 );
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++;
}