The code is as below:
public class examplecode {
public static void main(String[] args) {
int p1 = Integer.parseInt(args[0]);
int p2 = Integer.parseInt(args[1]);
int p3 = (p1^2)*(p2^2);
System.out.println(p3);
}
}
However, when I run the code, I get the error said
"C:\Program Files\Java\jdk-16.0.2\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2021.2\lib\idea_rt.jar=60813:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2021.2\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\Desktop\Sample1\out\production\Samplefolder examplecode
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
at examplecode.main(examplecode.java:4)
Process finished with exit code 1
Why I get such error?
I searched some resources said, I need to write down the following code in the terminal (10 and 20 are just randomly generated example inputs)
$ java examplecode 10 20
However, my terminal still shows error and did not give me any result
PS C:\Users\Desktop\Samplefolder> java examplecode 10 20
Error: Could not find or load main class examplecode
Caused by: java.lang.ClassNotFoundException: examplecode
I am thinking that as args[0] and args[1] indicates the first and second elements in the string, shall I create a string inside main function? Or where should I set that string?