Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fileWork;
- import java.io.File;
- import java.io.IOException;
- import java.io.PrintWriter;
- public class Main {
- public static void main(String[] args) throws IOException {
- int userNum= 100;
- String fileName = "boom.txt"; //for test
- sevenBoom(fileName, userNum);
- }
- // file path C:\res\boomb.txt
- public static void sevenBoom(String fileName, int userNum) throws IOException {
- //creating new file and its PrintWriter to write in
- File f = new File("C:\\res\\"+fileName);
- f.createNewFile();
- PrintWriter pw = new PrintWriter(f);
- //go throught all numbers untill user's number
- for (int i = 1; i<userNum;i+=1) {
- //using help function which check if a number is 7Boom
- if (containSeven(i)) {
- pw.print("7Boom!");
- pw.println();
- } else {
- pw.print(i + " ");
- }
- }
- pw.close();
- }
- public static boolean containSeven(int num) {
- int temp;
- //true for numbers which could be divided by 7
- if (num%7==0&&num%10!=0){
- return true;
- }
- //thue for numbers which contains digit 7
- while (num != 0) {
- temp = num % 10;
- if (temp%7==0&&temp%10!=0){
- return true;
- }
- num /= 10;
- }
- // for all others false
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment