Advertisement
JeffGrigg

MyWriter of Numbers

Sep 21st, 2018
508
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.66 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.IOException;
  3. import java.io.PrintWriter;
  4.  
  5. public class MyWriter {
  6.     public static void main(String[] args) {
  7.         System.out.println("Starting...");
  8.         String fileName = "numbers.txt";
  9.         try (PrintWriter writer = new PrintWriter(new File(fileName))) {
  10.             int sep = 1;
  11.             for (int i = 0; i < 10; i++) {
  12.                 sep++;
  13.                 writer.print(i);
  14.                 if (sep == 3) {
  15.                     writer.write("\n");
  16.                     sep = 1;
  17.                 }
  18.             }
  19.         } catch (final IOException ex) {
  20.             ex.printStackTrace();
  21.         }
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement