1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Ksju [112]
3 years ago
5

You coded the following class:

Computers and Technology
1 answer:
Oxana [17]3 years ago
8 0

Answer:

The code above tries to read a file using the scanner class in java programming language.

But it was done properly.

First, the scanner class library is not imported to the program.

Second,the syntax used in this program is an invalid way of reading a file in java programming language using the scanner class.

Lastly, "String s = file.nextLine();" is not a proper way of reading each line

To correct this problem; use the following code;

import java.util.Scanner;

import java.io.File;

import java.io.FileNotFoundException;

public class ReadFileWithScanner {

try

{

public static void main(String args[]) throws FileNotFoundException {

File text = new File("data.txt");

Scanner file = new Scanner(text);

int lines = 1;

while(file.hasNextLine()){

String line = filw.nextLine();

System.out.println("line " + lines + " :" + line);

lines++;

}

catch (ArithmeticException ae)

{

System.out.println(ae.getMessage());

}

}

}

You might be interested in
Maria is comparing her history project's second-place award to her classmate's first-place award. She starts planning how to win
weeeeeb [17]

Answer:

i would say long term

Explanation:

if she is planning for a while on how she is gonna get the first place award and its a long period of time before the next history project i would go with long term

5 0
3 years ago
Read 2 more answers
Which is the correct expansion of the term Internet? 
kirill115 [55]

Answer:

international network

Explanation:

8 0
4 years ago
Read 2 more answers
A _____________ is designed for a individual user.
pishuonlain [190]

Answer:

i don't know it sorry

Explanation:

7 0
3 years ago
Energía de movimiento de los átomos o moléculas
olasank [31]

Answer:

g

Explanation:

4 0
3 years ago
What's the best way to change the font size of all your notes pages at once?
pav-90 [236]

i think number 9 is c.

5 0
4 years ago
Other questions:
  • Unix has experimented with several security programs. a user can attach a watchdog program to a file that grants or denies acces
    13·1 answer
  • What is an additional clock tab
    11·1 answer
  • What is the voltage drop across R4 in the diagram shown above?
    13·1 answer
  • After adding an email account, how do you switch accounts to send a message?
    10·2 answers
  • Which method of accessing FTP has the most limited capabilities?
    9·2 answers
  • If you’re paid hourly and work 40 hours in one week how much overtime have you worked? 8 hours none $48 or $80
    9·2 answers
  • I NEED HELP ASAP
    8·1 answer
  • Brendan needs to edit all the slides in a presentation by adding a company logo and a header and footer. Which is
    13·2 answers
  • Select the correct answer.
    15·1 answer
  • A numeric test score is to be converted to a letter grade of A, B, or C according to the following rules: A score greater than 9
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!