Question: JAVA only why do i have that error message? Write a program that opens an output file named numbers.txt . The program should write the

JAVA only

why do i have that error message?

Write a program that opens an output file named numbers.txt . The program should write the integer values 1 through 49 to the file, with each number written on its own line in the file. Be sure to close the file when you are finished with it.

import java.io.FileWriter; import java.io.IOException;

public class Main { public static void main(String[] args) throws IOException { FileWriter fileWriter = new FileWriter("numbers.txt");

for (int i = 1; i < 50; i++) { fileWriter.write(i + " "); }

fileWriter.close(); } }

1. WriteFile.java:6: error: class Main is public, should be declared in a file named Main.java

2. public class Main {

3. ^

4. 1 error

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!