Java Methods
Can anyone help me to fix the error with the following code please?
import java.util.Scanner;
public class Main {
public static void main (String [] args){
COMPOSITE();
}
public int COMPOSITE(int number, int digit, int x, int y){
digit =2;
x=1;
y=0;
Scanner input = new Scanner (System.in);
System.our.println("Enter a Number.");
number = input.nextInt();
for (digit = 2; digit < number;digit++){
if (number%digit==0)
break;
}
if (number==digit){
return y;
}
else {
return x;
}
}
}
Voters
Yes, but next time please link a repl instead of copy-pasting the code.
Here are the problems with your code:
In general, if you receive arguments from COMPOSITE there is no reason to set them again in the code, or ask for input - either change COMPOSITE to be with no arguments or don't set it in the code.
Hope this helped, and sorry for the delay :)
@AlephZero Thanks a lot!!