I don’t know why my code is not letting me input any text as it should… my output is 0
Process finished with exit code 0
My code is
import java.util.Scanner;
public class MyThirdHomework {
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
System.out.println("Please enter your name:");
String a=scan.nextLine();
System.out.println("Please enter your surname");
String b=scan.nextLine();
System.out.println("Please enter your ID:");
int c=scan.nextInt();
System.out.println("Your name is:" + a);
System.out.println("Your surname is:" + b);
System.out.println("Your student ID is:" + c);
}
}
>Solution :
Your code is fine. It works for me. I suspect you are running in an IDE that is hiding the output from you. How are you running this code?
From a command line I ran:
javac MyThirdHomework.java
java MyThirdHomework
Please enter your name:
Scott
Please enter your surname
TheGreat
Please enter your ID:
42
Your name is:Scott
Your surname is:TheGreat
Your student ID is:42
When it is done the process exits without an error, which may be why whatever you were using says "Process finshed with exit code 0"
If you are running on Windows make sure the code runs with "java.exe" and not "javaw.exe"