anyone know why the process finishes before I can do another input?

Viewed 6

My goal for this program is to be able to define three values in an array by putting them into the console, then being able to ask for one of the values. I'm able to insert the three array values, but I am unable to call for one.

    int[] serialArray;
    Scanner in = new Scanner(System.in);
    serialArray = new int[3];

    int a = in.nextInt();
    serialArray[0] = a;
    int b = in.nextInt();
    serialArray[1] = b;
    int c = in.nextInt();
    serialArray[2] = c;

    System.out.println("Please request array value below");
    String r = in.nextLine();

    if (r == "1") {
        System.out.println(a);
    }else if(r == "2"){
        System.out.println(b);
    }else if(r == "3"){
        System.out.println(c);
    }

}
0 Answers
Related