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.

6th Oct 2021, 10:47 AM
ruiririririri
ruiririririri - avatar
5 Respuestas
+ 3
call your class Main instead of main. ☺️
6th Oct 2021, 10:54 AM
Stefanoo
Stefanoo - avatar
+ 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 =)
6th Oct 2021, 11:04 AM
Rishi
Rishi - avatar
+ 1
Hi Rishi Thank you very much! I really appreciate it. You’re very kind. Have a nice day!
6th Oct 2021, 11:13 AM
ruiririririri
ruiririririri - avatar
+ 1
ruiririririri tnx, you too o((*^▽^*))o
6th Oct 2021, 1:04 PM
Rishi
Rishi - avatar
0
Stefanoo Thank you very much! I really appreciate it. Have a nice day!
6th Oct 2021, 11:11 AM
ruiririririri
ruiririririri - avatar