• Register
3 votes
1.1k 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

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,240 points

Related questions

0 votes
1 answer 16 views
16 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 Daniel Aguilar
1 vote
1 answer 16 views
16 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 LizzyM 6.1k points
0 votes
1 answer 54 views
54 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
1 vote
1 answer 23 views
23 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 LizzyM 6.1k points