chaibs

file

Mar 4th, 2018
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  1. package Main;
  2.  
  3. import java.io.File;
  4. import java.io.FileNotFoundException;
  5. import java.io.IOException;
  6. import java.io.PrintWriter;
  7.  
  8. public class MainEvent {
  9.  
  10.     public static void main(String[] args) throws IOException {
  11.         createFile("newFile.txt", 100);
  12.     }
  13.  
  14.     public static void createFile(String filename, int num) throws FileNotFoundException {
  15.         PrintWriter pw = new PrintWriter(new File(filename));
  16.  
  17.         for (int i = 1; i < num; i += 1) {
  18.             if (i % 7 == 0 || (checkNum(i)) == 7) {
  19.                 pw.println("BOOM!");
  20.             } else {
  21.                 pw.println(i);
  22.             }
  23.         }
  24.  
  25.         pw.close();
  26.     }
  27.  
  28.     public static int checkNum(int i) {
  29.         int newNum = 0;
  30.         while (i > 0) {
  31.             if (i % 10 == 7) {
  32.                 return i % 10;
  33.             }
  34.             i /= 10;
  35.         }
  36.         return newNum;
  37.     }
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment