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
7
  • 3
    There is no readInt() method in Console class. What do you want to do? Do you want to read user input? Commented Nov 4, 2015 at 12:23
  • Is there any method say readInt() ? I guess no. Commented Nov 4, 2015 at 12:24
  • I want to read user input as an int, like readLine(). Commented Nov 4, 2015 at 12:24
  • I´d also consider to not use System.console(), because it might return null depending on the enviroment it´s beeing executed on. Commented Nov 4, 2015 at 12:25
  • Use scanner Commented Nov 4, 2015 at 12:25

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.