Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /* ==================================================
- Chapter 2: Syntax section B- Loops
- Ex8: 7 Boom Game
- ===================================================
- */
- public class MyProgram {
- public static void main(String[] args) {
- //variables
- int number; //represent the loop's range [1,number]
- Scanner s=new Scanner(System.in);
- //user input
- System.out.println("Enter a number: ");
- number=s.nextInt();
- System.out.println("\n*** 7 Boom Game ***\n");
- //loop's range [1,number]
- for(int i=1;i<=number;i++){
- //if i multiplied by 7 print Boom, if not print the number
- if ( i % 7 == 0 ) {
- System.out.print("Boom ");
- } else {
- System.out.print(i + " ");
- }
- }
- System.out.println("\n\n*** End ***");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment