The question is
Write a method isMultiple that determines, for a pair of integers , whether the second integer is a multiple of the first. The method should take two integer arguments and return true if the second is a multiple of the first and false otherwise.
[Hint: Use the remainder operator .] Incorporate this method into an application that inputs a series of pairs of integers (one pair at a time) and determines whether the second value in each pair is a multiple of the first.har()
Here is my code
import java.util.*;
public class Multiples {
public static void main(String [] args){
boolean run = true;
while(run = true){
System.out.print("Enter one number:");
Scanner input = new Scanner(System.in);
int num1 = input.nextInt();
int num2 = input.nextInt();
System.out.println("Do you want to enter another pair(y/n)?");
String a = input.next();
boolean result = isMultiple(num1, num2);
if(result = true){
System.out.println(num1 + " is a multiple of " + num2);
}
else{
System.out.println(num1 + " is not a multiple of " + num2);
}
if(YesOrNo(a)){
break;
}
}
}
public static boolean YesOrNo(String a){
if(a == "y")
return false;
else if(a == "n")
return true;
else
return true;
}
public static boolean isMultiple (int x , int y)
{
if(x % y == 0 || y % x == 0)
return true;
else
return false;
}
}
I want break the while when enter "n" but it is break no matter what I enter.