Implemented Divisibility, IsDivisible
This commit is contained in:
parent
9cc440b16d
commit
5f46eb358e
@ -1,5 +1,7 @@
|
||||
package divisibility;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
//This program reads in two numbers from the user, dividend and divisor, and prints out whether dividend is evenly divisible by divisor.
|
||||
//
|
||||
// For example, one run of the program may look like this:
|
||||
@ -18,8 +20,34 @@ package divisibility;
|
||||
|
||||
|
||||
public class Divisibility {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
|
||||
// Get input
|
||||
Scanner scan = new Scanner(System.in);
|
||||
int dividend; // Stores the dividend input
|
||||
int divisor; // Stores the divisor input
|
||||
String status = " is not";
|
||||
|
||||
// Prompt for dividend
|
||||
System.out.print("Enter the dividend: ");
|
||||
dividend = scan.nextInt();
|
||||
|
||||
// Prompt for divisor
|
||||
System.out.print("Enter the divisor: ");
|
||||
divisor = scan.nextInt();
|
||||
|
||||
// Determine divisibility, and change the status only if divisible
|
||||
if (dividend % divisor == 0)
|
||||
{
|
||||
status = " is";
|
||||
}
|
||||
|
||||
// Print the result
|
||||
System.out.println(dividend + status + " divisble by " + divisor);
|
||||
|
||||
// kill the scanner
|
||||
scan.close();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,4 +7,12 @@ package isDivisible;
|
||||
//public boolean isDivisible(int a, int b)
|
||||
|
||||
public class IsDivisible {
|
||||
public boolean isDivisible(int a, int b)
|
||||
{
|
||||
if (a % b == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user