Advertisement
petkouzunski

p06_numbergenerator

Aug 31st, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.36 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class p06_numbergenerator {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int m = Integer.parseInt(scanner.nextLine());
  7.         int n = Integer.parseInt(scanner.nextLine());
  8.         int l = Integer.parseInt(scanner.nextLine());
  9.  
  10.         int special = Integer.parseInt(scanner.nextLine());
  11.         int control = Integer.parseInt(scanner.nextLine());
  12.  
  13.         boolean nextline = false;
  14.         boolean specialreached = false;
  15.  
  16.         int number = m*100+n*10+l;
  17.  
  18.         for (int i = number; i >= 111; i--) {
  19.             if (i % 3 == 0 && !nextline) {
  20.                 special += 5;
  21.                 nextline = true;
  22.             } else if (i % 10 == 5 && !nextline) {
  23.                 special -= 2;
  24.                 nextline = true;
  25.             } else if (i % 2 == 0 && !nextline) {
  26.                 special *= 2;
  27.                 nextline = true;
  28.             }
  29.             nextline = false;
  30.             if (special >= control) {
  31.                 specialreached = true;
  32.                 break;
  33.             }
  34.         }
  35.  
  36.         if(specialreached){
  37.             System.out.printf("Yes! Control number was reached! Current special number is %d.",special);
  38.         } else {
  39.             System.out.printf("No! %d is the last reached special number.",special);
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement