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 Antworten
+ 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!