i have a question in my textbook that says:
Write a method multiple that takes two integers as its arguments and returns true if the first integer is divisible
evenly by the second one (i.e., there is no remainder after division); otherwise, the method should
return false. Incorporate this method into an application that enables the user to enter values to test the
method.
and i wrote this code but its not working:
public class project1 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int a, b;
System.out.println("enter the first number");
a = input.nextInt();
System.out.println("enter the first number");
b = input.nextInt();
}
public static boolean multiple(int g, int c) {
int g, c;
if (g % c = 0) {
return true;
} else {
return false;
};
}
}
First of all you don’t need to declare
gandcagain in the functionmultiple(It is an error). Second, you didn’t call the function at all, you just implemented it. And like other people answered, you need to have==instead of=.Note that you can have a shorter version of
multiplewhich have only one line:return g%c==0;