Guest User

Untitled

a guest
Jun 18th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. // BeepBoop.java
  2. // Josh Yetter
  3.  
  4. import java.util.Scanner;
  5. public class BeepBoop
  6. {
  7.    // prompts for and reads in a positive integer limit
  8.    // prints each number from 1 to limit and replaces number
  9.    // by 'Beep' if divisible by 3, by 'Boop' if divisible by 5 and 'BeepBoop' if divisible by both
  10.    public static void main( String[] args )
  11.    {
  12.       Scanner scan = new Scanner(System.in);
  13.        
  14.       System.out.println("Enter a positive integer:");
  15.       int limit = scan.nextInt();
  16.       int count = 1;
  17.        
  18.       while (count < limit)
  19.       {
  20.          if (count % 3 == 0 && count % 5 == 0)
  21.             System.out.println("BeepBoop");
  22.          else if (count % 3 == 0)
  23.             System.out.println("Beep");
  24.          else if (count % 5 == 0)
  25.             System.out.println("Boop");
  26.          else
  27.             System.out.println(count);
  28.          count++;
  29.       }
  30.    }
  31. }
Add Comment
Please, Sign In to add comment