• + 1 comment

    I am having problem to my Java code.

    the test case 1 says Compiler message: Runtime Error If using my Option 1 on searchName() method and if I want to use my Option 2 which is infinite loop for inputs. the test cases are all red. So I have a good chance if I use my Option 1

        public void searchName(){
            for(int i= 0; i < getN(); i++){      //Option 1
                enteredName.add(myScanner.nextLine());
                
            }
            // while(true){        //Option 2
            //     String string = myScanner.nextLine();
            //     if(phoneBook.containsKey(string)){
            //         System.out.println(string + " = " + phoneBook.get(string));
            //     } else {
            //         System.out.println("Not Found");
            //     }
            // }
        }
        public void outputSearchName(){
            for(int i = 0; i < getN(); i++){
                if(phoneBook.containsKey(enteredName.get(i))){
                    System.out.println(enteredName.get(i) + "=" + phoneBook.get(enteredName.get(i)));
                } else {
                    System.out.println("Not found");
                }
            }
        }