apez1

Assignment 3: Crack the Code!

Sep 24th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.66 KB | None | 0 0
  1. package project;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Assignment2 {
  6.  
  7.     public static void main(String[] args) {
  8.  
  9.         int flag = 0;
  10.         Scanner scanner = new Scanner(System.in);
  11.         System.out.println("Welcome. What is your name?");
  12.         String name = scanner.nextLine();
  13.         System.out.println("Hello " + name + "." + " Try your best to crack the code!");
  14.            
  15.         while(flag == 0) {
  16.            
  17.         System.out.println("PHASE 1");                                      //phase 1
  18.         System.out.println("Enter a number :");
  19.         int num1 = scanner.nextInt();
  20.             if(num1 != 3) {
  21.                 flag = 1;
  22.                 System.out.println("Sorry, that was incorrect!");
  23.                 System.out.println("Better luck next time!");                  
  24.             }
  25.             else {
  26.                 System.out.println("Correct!");
  27.             }
  28.        
  29.         int num69 = 0; 
  30.         if(num1 == 3) {
  31.             System.out.println("\nPHASE 2");                                    //phase 2
  32.             System.out.println("Enter a number :");
  33.             int num2 = scanner.nextInt();                                   //phase 2
  34.             if(num2 == 1 | (num2 >= 33 & num2 <= 100) ) {
  35.                 System.out.println("Correct!");
  36.                 num69 = 1;
  37.             }
  38.             else {
  39.                 flag = 1;
  40.                 System.out.println("Sorry, that was incorrect!");
  41.                 System.out.println("Better luck next time!");              
  42.             }                          
  43.         }
  44.        
  45.         if(num69 == 1) {
  46.             System.out.println("\nPHASE 3");                                    //phase 2
  47.             System.out.println("Enter a number :");
  48.             int num3 = scanner.nextInt();
  49.             if(num3 > 1 && (num3 % 3 == 0 || num3 % 7 == 0)){
  50.                 System.out.println("Correct!");
  51.                 System.out.println("You have cracked the code!");
  52.                 flag = 2;
  53.             }
  54.             else {
  55.                 flag = 1;
  56.             System.out.println("Sorry, that was incorrect!");
  57.             System.out.println("Better luck next time!");                  
  58.             }
  59.           }
  60.            
  61.            
  62.         }
  63.        
  64.     }
  65.                
  66.                
  67. }
Add Comment
Please, Sign In to add comment