This program will determine if a number is divisible by 5 or not. This should be a simple task by now, but this time you will use a static method to do the checking. The method should be called divFive and will take in one integer. The code inside your method will check to see if the number passed is evenly divisibly by 5. If it is, the method will return a boolean true. If not, a boolean false. (The return type will be boolean, not a String.) In your main method, you will ask the user for input, accept the input, and then call your divFive method, passing in the user’s integer. With the Boolean result that you get back from the divFive method, you should have code that will print “Divisible by 5” if a true is returned and “Not divisible by 5” if a false is returned. This program MUST have a try/catch block to: Catch wrong data types (input mismatch) Catch values 0 or less (custom exception) The try/catch block should go in your main method since this is where you are getting the user input. Make sure it’s in a loop so that you can keep asking for input if the user does not enter something valid. Your whole program does NOT need to loop continuously but you DO need a loop for your try/catch so that we can continue to request an appropriate input if the user does not follow directions. in java
-
This program will determine if a number is divisible by 5 or not. This should be a simple task by now, but this time you will use a static method to do the checking.
-
The method should be called divFive and will take in one integer. The code inside your method will check to see if the number passed is evenly divisibly by 5. If it is, the method will return a boolean true. If not, a boolean false. (The return type will be boolean, not a String.)
-
In your main method, you will ask the user for input, accept the input, and then call your divFive method, passing in the user’s integer.
-
With the Boolean result that you get back from the divFive method, you should have code that will print “Divisible by 5” if a true is returned and “Not divisible by 5” if a false is returned.
-
This program MUST have a try/catch block to:
-
Catch wrong data types (input mismatch)
-
Catch values 0 or less (custom exception)
-
-
The try/catch block should go in your main method since this is where you are getting the user input. Make sure it’s in a loop so that you can keep asking for input if the user does not enter something valid.
-
Your whole program does NOT need to loop continuously but you DO need a loop for your try/catch so that we can continue to request an appropriate input if the user does not follow directions.
in java
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 4 images