Consider a text file called input.txt that contains the following three lines: 2
ID: 3631473 • Letter: C
Question
Consider a text file called input.txt that contains the following three lines:20 30 43 are some positive numbers.
Their average is: 31.0
That's it!
The line that begins "20 30" is the first line in the file, and the line "That's it!" is the last line in the file.
Given the file above, what is the output of the following code fragment?
Scanner input = new Scanner(new File("input.txt"));
int count = 0;
while (input.hasNextLine()) {
System.out.println(input.nextLine());
count++;
}
System.out.println("count: " + count);
Given the file above, what is the output of the following code fragment?
Scanner input = new Scanner(new File("input.txt"));
int count = 0;
while (input.hasNext()) {
System.out.println(input.next());
count++;
}
System.out.println("count: " + count);
Given the file above, what is the output of the following code fragment?
Scanner input = new Scanner(new File("input.txt"));
int count = 0;
while (input.hasNextInt()) {
System.out.println(input.nextInt());
count++;
}
System.out.println("count: " + count);
Given the file above, what is the output of the following code fragment?
Scanner input = new Scanner(new File("input.txt"));
int count = 0;
while (input.hasNextDouble()) {
System.out.println(input.nextDouble());
count++;
}
System.out.println("count: " + count);
Explanation / Answer
please rate - thanks
Consider a text file called input.txt that contains the following three lines:
20 30 43 are some positive numbers.
Their average is: 31.0
That's it!
The line that begins "20 30" is the first line in the file, and the line "That's it!" is the last line in the file.
Given the file above, what is the output of the following code fragment?
Scanner input = new Scanner(new File("input.txt"));
int count = 0;
while (input.hasNextLine()) {
System.out.println(input.nextLine());
count++;
}
System.out.println("count: " + count);
20 30 43 are some positive numbers.
Their average is: 31.0
That's it!
count: 3
Given the file above, what is the output of the following code fragment?
Scanner input = new Scanner(new File("input.txt"));
int count = 0;
while (input.hasNext()) {
System.out.println(input.next());
count++;
}
System.out.println("count: " + count);
20
30
43
are
some
positive
numbers.
Their
average
is:
31.0
That's
it!
count: 13
Given the file above, what is the output of the following code fragment?
Scanner input = new Scanner(new File("input.txt"));
int count = 0;
while (input.hasNextInt()) {
System.out.println(input.nextInt());
count++;
}
System.out.println("count: " + count);
20
30
43
count: 3
Given the file above, what is the output of the following code fragment?
Scanner input = new Scanner(new File("input.txt"));
int count = 0;
while (input.hasNextDouble()) {
System.out.println(input.nextDouble());
count++;
}
System.out.println("count: " + count);
20.0
30.0
43.0
count: 3
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.