Skip to content
← Back to Community
Java Methods
Profile icon
pramod_khatri

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
Profile icon
Wrnitto273
Comments
hotnewtop
Profile icon
AlephZero

Yes, but next time please link a repl instead of copy-pasting the code.

Here are the problems with your code:

  1. When you called COMPOSITE in the main function, you did not provide any arguments.
  2. COMPOSITE should be static (public static int COMPOSITE(..)).
  3. Instead of System.our.println("Enter a Number."), you should write System.out.println("Enter a Number.")

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 :)

Profile icon
pramod_khatri

@AlephZero Thanks a lot!!

Profile icon
RenanCarneiro2