Skip to content
Advertisement

java Linked List for swapping two numbers

I amgetting errors in my code. The errors are: error: class SwapNodes is public, should be declared in a file named SwapNodes.java public class SwapNodes {
^ Main.java:104: error: Illegal static declaration in inner class SwapNodes.Main public static void main(String[] args) {
^ modifier ‘static’ is only allowed in constant variable declarations My program is as follows:

JavaScript

Advertisement

Answer

class SwapNodes is public, should be declared in a file named SwapNodes.java this means since the class is public, the file name must be SwapNodes instead of Main. Change the filename to SwapNodes.

Output will be :

JavaScript

Note : Always try to name the file whatever you are giving as public class. eg : public class ClassName must be in a file ClassName.java.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement