0

This is my code:

import java.io.PrintWriter;
import java.io.FileNotFoundException;

public class Main {
public static void main(String[] args) throws FileNotFoundException {

    String enter = "Enter";
    String resolve = "Resolve";
    String store = "Store";

    // if file doesn't exist
    int nextjob = 1;
    int jobnumber = nextjob;
    int phonenumber = System.console().readInt();
    int numberoflines = System.console().readInt();
    String problem = System.console().readLine();
    int time = System.console().readInt();

    String command = System.console().readLine();
    if(command.equals(store)){
        PrintWriter writer = new PrintWriter("openjobs.txt");
        writer.println(nextjob);
        writer.println(jobnumber);
        writer.println(phonenumber);
        writer.println(numberoflines);
        writer.println(problem);
        writer.println(time);
        writer.close();
    }
  }
}

This is the output:

Main.java:14: error: cannot find symbol
        int phonenumber = System.console().readInt();
                                          ^
symbol:   method readInt()
location: class Console
Tunaki
  • 132,869
  • 46
  • 340
  • 423
Lexhanatin
  • 3
  • 1
  • 5

1 Answers1

4

Use Scanner and Scanner.nextInt() method to take only Integer as input from the user.

Scanner sc = new Scanner(System.in);
int anyNumber = sc.nextInt();

If the user gives an input which is not an integer, it will throw an InputMismatchException.

JRodDynamite
  • 12,325
  • 5
  • 43
  • 63