
I'd like to print the first N integers, that is, "1, 2, 3, 4, ..., N-1, N", say N equals 1000, or 10000 or whatever. I'd also like to have the result stored as a file instead of having it only on the screen. How should I do it?

Hi Friend,
Try the following code:
import java.io.*;
class PrintNumbers{
public static void main(String[] args) throws Exception{
FileWriter fstream = new FileWriter(new File("numbers.txt"),true);
BufferedWriter out = new BufferedWriter(fstream);
int N=10000;
for(int i=1;i<=N;i++){
System.out.println(i);
out.write(Integer.toString(i));
out.newLine();
}
out.close();
}
}
Thanks
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.