-3

My code:

import java.util.Scanner;
import java.io.Reader;    #I also tried to do this, it didnt help
public class firstClass {

    public static void main(String[] args) {  
    System.out.println("how many player?");  #this output works if I delate the reader in the line
    int a = reader.nextInt();                #for some reason it shows error for reader
    }

}

The error:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    reader cannot be resolved

    at firstClass.main(firstClass.java: 7)

And also it doesn't show any error if I just remove the line of the reader

plsHelpMe
  • 15
  • 6
  • 1
    Does this answer your question? [What does a "Cannot find symbol" or "Cannot resolve symbol" error mean?](https://stackoverflow.com/questions/25706216/what-does-a-cannot-find-symbol-or-cannot-resolve-symbol-error-mean) – OH GOD SPIDERS Jan 07 '22 at 10:42
  • no, I've also checked it in other computers and it worked, idk what is wrong now. Thank u anyway :) – plsHelpMe Jan 07 '22 at 10:48

1 Answers1

0
import java.util.Scanner;

class Main { 
    
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in); 
    
    System.out.println("Enter your name");
    String name = scanner.nextLine();
    System.out.println("your name is " + string); 
    
    System.out.println("Enter your age");    
    int number = scanner.nextInt();
    System.out.println("Your age is " + number);     
  }
}

To compile, write on you terminal:

javac Main.java

To run, write on you terminal:

java Main
  • it also does not work, it shows the error: `Error: Could not find or load main class firstClass Caused by: java.lang.ClassNotFoundException: firstClass ` – plsHelpMe Jan 07 '22 at 10:51
  • To run java from command line: javac Main.java // this compile java main // this run – max de simone Jan 07 '22 at 10:55