public class summa { public static void main(String[]args) { Scanner input=new Scanner(System.in); int param1,param2,sum; param1=input.nextInt(); param2=input.nextInt(); sum=param1+param2; System.out.println(sum); } } file.java on line 2: error: Illegal static declaration in inner class _runeatuj.summa public static void main(String[]args) { ^ modifier 'static' is only allowed in constant variable declarations 1 error 

Console from the codefights website, connected libraries by default:

 import java.io.*; import java.util.*; import java.math.*; import java.util.regex.*; import java.util.stream.*; import java.text.*; import java.security.SecureRandom; import java.util.function.*; import java.util.concurrent.*; 

Google on this topic but still did not understand what the problem is, please clarify

screenshot

Thank you all, figured out, the problem is solved by this code

 int add(int param1, int param2){ return param1+param2; } 
  • one
    Either you don’t say anything to us and it’s not the whole code, or ... yes, no, you don’t agree to it - JVic
  • I indicated everything as it is. I attached a screenshot, everything is the same. - Zebsier
  • four
    Maybe the matter is that the task is written clearly: write a function... , and you not only write it inside the class, also call static main . Read the condition carefully. - selya

1 answer 1

It is obvious from the error message that static allowed to be used only for declaring variables.

PS You were also given a hint that you need to write the helloWorld(String) function, and not the main(String[]) method