hello i am new to java. I don't get why tempNumber only catches 2 digit numbers. and when I choose "2" it doesnt respond first time. When it displays the menu again and I enter again "2" then it works.
import java.io.*; //import java.math.*; public class java_prime{ //We will create two class arrays, these //Can be used by all the methods in the class static int number[] = new int[100]; static String name[] = new String[100]; //We will create a counter, this will help us //remember how many names and numbers we are storing static int counter = 0; //Main method public static void main(String[] args) throws IOException{ String tempName = null; int tempNumber = 0; //Create a Buffered reader for input, you do remember how don't you? BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); //Here we output our Menu displayMenu(); //Here we get user input String temp = in.readLine(); //Loop until the use wants to quit while(temp!="3"){ if(temp.equals("1")){ System.out.print("Enter a new Name: "); tempName = in.readLine(); System.out.println(); System.out.print("Enter a new Number: "); tempNumber = in.read(); //Here we call the method to add the record addEntry(tempName, tempNumber); }else if(temp.equals("2")){ //In here we call the method to output the records showRecords(); } //Display the menu again and ask for input again displayMenu(); temp = in.readLine(); } } //Here is all the methods you will need! public static void addEntry(String tempName, int tempNumber){ name[counter] = tempName; number[counter] = tempNumber; counter++; } public static void displayMenu(){ System.out.println("\n\n\n"); System.out.println("WELCOME TO THE JAVA PDA - DESKTOP VERSION\n\nWhat would you like to do today?\n\n1. Enter a new Name and Number\n2. View all names and Numbers\n3. Quit"); } public static void showRecords(){ int i; System.out.println("Name\t\t\t\tNumber"); for(i = 0; i!=counter;i++){ System.out.println(name[i]+"\t\t\t\t"+number[i]); } } }