0
[WHAT IS WRONG WITH MY CODE] Checks whether the inputted age is a âMinorâ or an âAdultâ
import java.util.Scanner; public class main { public static void main(String[] args) { ageCheck(); } public static void ageCheck() { Scanner input = new Scanner(System.in); int age = input.nextInt(); System.out.println(age); if (age > 12) { System.out.println("Adult"); } else { System.out.println("Minor"); } } } (It says âMain.java:3: error: class main is public, should be declared in a file named main.javaâ) I tried applying what Iâve learned so far...and I still donât get it.
5 RĂ©ponses
+ 3
call your class Main instead of main. âșïž
+ 2
You have the class name same as the main function's name. So a naming collision occurred.
PS: Don't call yourself dumb. All the best =)
+ 1
Hi Rishi Thank you very much! I really appreciate it. Youâre very kind. Have a nice day!
+ 1
ruiririririri tnx, you too
o((*^âœ^*))o
0
Stefanoo Thank you very much! I really appreciate it. Have a nice day!