I was trying to run a java program from terminal. So I compiled the code using javac FileName.java
and then tried to execute that by java ClassName
and also tried java ClassName.class
. I am trying very basic code like printing 'Hello World' and the java file is not inside any packages also. But in Command line it is throwing error like :
But in the folder class file is being generated.
Can anyone help me what is the problem?
I tried to uninstall and reinstall java SE 17 (jdk 17.0.1) but it is still not working. And one more thing is that if I try to run that through VS Code or any code editor it is properly running there.
A.java File:-
import java.util.*;
public class A
{
static public void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter two number: ");
int n1,n2;
n1 = sc.nextInt();
n2 = sc.nextInt();
System.out.println("Sum of "+n1+" and "+n2+" is equal to : "+(n1+n2));
}
}