Assume a Scanner reference variable namedinput has been declared, and it is associated with a file that contains lines of text. Also assume that an int variable named count has been declared, but has not been initialized. Write the code necessary to count the lines of text in the file and store that value in count.

Programming with Microsoft Visual Basic 2017
8th Edition
ISBN:9781337102124
Author:Diane Zak
Publisher:Diane Zak
Chapter9: Sequential Access Files And Menus
Section: Chapter Questions
Problem 7MQ2
icon
Related questions
Question

java

Assume a Scanner reference variable named input has been declared, and
it is associated with a file that contains lines of text. Also assume that an int
variable named count has been declared, but has not been initialized. Write
the code necessary to count the lines of text in the file and store that value in
count.
1 Enter your code
Transcribed Image Text:Assume a Scanner reference variable named input has been declared, and it is associated with a file that contains lines of text. Also assume that an int variable named count has been declared, but has not been initialized. Write the code necessary to count the lines of text in the file and store that value in count. 1 Enter your code
Expert Solution
Step 1

Program is written. If we not initialize the count variable, we will get compile time error. So count variable must be initialized.

Algorithm:

Step 1: Write main() method

Step 2: Declare and define the count variable with 0 (int count = 0)

Step 3: Load the inputFile.txt lines using File file = new File("inputFile.txt");

Step 4: Declare and define Scanner input = new Scanner(file);

Step 5: Using while loop count the number of lines in the given lines and store the count in count variable

Step 6:  Close the input

 

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
Header Files
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT