Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // BeepBoop.java
- // Josh Yetter
- import java.util.Scanner;
- public class BeepBoop
- {
- // prompts for and reads in a positive integer limit
- // prints each number from 1 to limit and replaces number
- // by 'Beep' if divisible by 3, by 'Boop' if divisible by 5 and 'BeepBoop' if divisible by both
- public static void main( String[] args )
- {
- Scanner scan = new Scanner(System.in);
- System.out.println("Enter a positive integer:");
- int limit = scan.nextInt();
- int count = 1;
- while (count < limit)
- {
- if (count % 3 == 0 && count % 5 == 0)
- System.out.println("BeepBoop");
- else if (count % 3 == 0)
- System.out.println("Beep");
- else if (count % 5 == 0)
- System.out.println("Boop");
- else
- System.out.println(count);
- count++;
- }
- }
- }
Add Comment
Please, Sign In to add comment