• Register
3 votes
2k views

Problem:

Hello Kodlogs,

I am a novice Java programmer. I just wrote my very first program a few minutes earlier. Now I want to write a program that can add two different integer numbers for me.
I guess I done my coding well but it says something wrong with my writing and throws back an error: “at least one public class is required in the main file

Please find my code snippet below to understand my problem well.

Thanks all.

class AddingNumbers{
     public static void main(String []args){
         int x = 10;
         int y = 15;
         int sum = x+y;
        System.out.println("Sum is: " + sum);
     }
}

 

12 7 7
15,250 points

Please log in or register to answer this question.

1 Answer

0 votes

Solution:

Hello Gavin, I hope you are enjoying programming with problem-solving. The problem occurred in the very first line of your program.

In java, you need to have at least one public class in your program otherwise it not gonna run. You may have multiple public classes but mandatory is t least one. I hope you get my point. Let’s write the program again with a public class,

public class AddingNumbers{
     public static void main(String []args){
         int x = 10;
         int y = 15;
         int sum = x+y;
        System.out.println("Sum is: " + sum);
     }
}

Now your program looks good and you are all set to go. This program should compile error-free and give an output:

Sum is: 25

 

13 9 6
94,260 points

Related questions

0 votes
1 answer 48 views
48 views
Hi, when i try to execute this code i always get the error message from above, and i really want to know why, already tried to put a “public class XXXX” before the code, but not work anyway. public static String invertirPalabras(String cadena) { cadena += " "; String ... + palabra; if (cadena.charAt(i) == ' ') { nuevaCadena += palabra; palabra = ""; } } return nuevaCadena.trim(); }
asked Aug 2, 2020 Daniel Aguilar
0 votes
1 answer 256 views
256 views
Problem: Hi there! I have been learning to program for a long time now and I recently learned inheritance in Java. I wrote the following program for practice: class Institutions { public void print_institutions() { System.out.println("This is an institution"); } } class ... , I have no idea what is causing this error. Can anybody here please clarify the cause of the error and its solution? Thanks!
asked Dec 29, 2020 Code Learner 9.8k points
1 vote
1 answer 52 views
52 views
Problem: I am totally new in programming language. So I tried to write a program using: public static void main(String args[]) But it seems to give error : public static void main(String args[]) ^ IndentationError: unexpected indent What should I do?
asked Apr 2, 2020 LizzyM 6.1k points
1 vote
1 answer 20 views
20 views
Problem: I Created a Loan.java and compile it with JDK 1.6 and Run Loan.class with JRE 1.5. C:\Program Files\Java\jre1.5.0_06\bin>java -version java version "1.5.0_06" The following thing gives an error message: C:\Program Files\Java ... Source)         at java.net.URLClassLoader.defineClass(Unknown Source)         at java.net.URLClassLoader.access$100(Unknown Source) what should i do next ..
asked Mar 27, 2020 LizzyM 6.1k points
0 votes
1 answer 78 views
78 views
Problem : I am facing following Error. Status 1 error, param missing, error because at least one required parameter is missing. Can anybody tell me the correct status code to give when the parameter is missing from the request? Is 400 the correct one? Or is it 404? [GET /search?q=ok] => 200 OK [GET /search] => 400 Bad Request? or 404 Not Found? Or 422 Unprocessable Entity? Others?
asked Dec 2, 2019 alecxe 7.5k points
0 votes
1 answer 20 views
20 views
java file with a default class access specifier get compiled?
asked Jan 24 TeamScript 13.5k points
0 votes
1 answer 37 views
37 views
Problem: anyone who know this problem please help at least one of the class levels is not a valid r variable name
asked Mar 15 Rohit kr 17.5k points
0 votes
1 answer 14 views
14 views
Problem : Please help me.-At Least One Method In An Abstract Class Must Be Abstract.?
asked Mar 15 sadi1982 36.3k points
1 vote
1 answer 11 views
11 views
Problem: While compiling a program I am getting this error: Error class is public should be declared in a file named.
asked Apr 27 PkGuy 23.5k points