Skip to content

Commit

Permalink
Update BuzzNumber.java
Browse files Browse the repository at this point in the history
Hello, This is my first commit... Im sorry if i did it wrong. I added functionality so that if number entered is negative it will prompt user to re-enter a positive number. Also added funtionality in a try catch block so that if user enters a non number it prompts user to enter a number before it would have errored out.
  • Loading branch information
jrodriq3 authored Mar 22, 2022
1 parent b2961f7 commit ddd7d3f
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions BuzzNumber.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,35 @@
public class BuzzNumber {

public static void main(String[] args) {
System.out.println("Input an integer: "); // Assumes input is a valid non-negative integer
Scanner in = new Scanner(System.in);
int checkBuzz = in.nextInt();
boolean isBuzzNumber = false;
if (checkBuzz % 7 == 0 || checkBuzz % 10 == 7){ // Checks if input can be divisible by 7 or ends with 7
isBuzzNumber = true;
boolean isPositive = false;
// while loop and isPositive flag will assure integer entered is positive
while (isPositive == false) {
int checkBuzz = -1;
System.out.println("Input an integer: ");
boolean validEntry = false;
// while loop with try catch to make sure input is valid integer
while (validEntry == false) {
try {
Scanner in = new Scanner(System.in);
checkBuzz = in.nextInt();
validEntry = true;
} catch (Exception e) {
System.out.println("You didn't enter an integer. Re-enter...");
}
}
// if statement to continue loop if input was a negative number.
if (checkBuzz < 0) {
continue;
}
boolean isBuzzNumber = false;
if (checkBuzz % 7 == 0 || checkBuzz % 10 == 7){ // Checks if input can be divisible by 7 or ends with 7
isBuzzNumber = true;
}
isPositive = true;
System.out.println("isBuzzNumber: " + isBuzzNumber);

}
System.out.println(isBuzzNumber);


}
}

1 comment on commit ddd7d3f

@tangorishi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey I am looking for my first contribution , I think I got a different approach to solve this problem please assign this problem to me.

Please sign in to comment.