hpilo

Chapter2_SyntaxB_Ex8

Dec 15th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.94 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. /*  ==================================================
  4.           Chapter 2: Syntax section B- Loops
  5.  
  6.             Ex8: 7 Boom Game
  7.     ===================================================
  8. */
  9.  
  10. public class MyProgram {
  11.     public static void main(String[] args) {
  12.  
  13.         //variables
  14.         int number;     //represent the loop's range [1,number]
  15.         Scanner s=new Scanner(System.in);
  16.  
  17.         //user input
  18.         System.out.println("Enter a number: ");
  19.         number=s.nextInt();
  20.  
  21.         System.out.println("\n*** 7 Boom Game ***\n");
  22.  
  23.         //loop's range [1,number]
  24.         for(int i=1;i<=number;i++){
  25.  
  26.             //if i multiplied by 7 print Boom, if not print the number
  27.             if ( i % 7 == 0 ) {
  28.                 System.out.print("Boom ");
  29.             } else {
  30.                 System.out.print(i + " ");
  31.             }
  32.  
  33.         }
  34.         System.out.println("\n\n*** End ***");
  35.  
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment