The output isItem[]items = new Item[4]; items[0]= new Item("n",2.2,4); items[0].setName("OJ"); items[0].setCost(6.00); items[0].setQty(10); items[1]= new Item("n",2.2,4); items[1].setName("Milk"); items[1].setCost(3.99); items[1].setQty(20); items[2]= new Item("n",2.2,4); items[2].setName("Snicker"); items[2].setCost(0.79); items[2].setQty(75); items[3]= new Item("n",2.2,4); items[3].setName("Wheat Bread"); items[3].setCost(2.49); items[3].setQty(5); items[0].getName(); items[0].getCost(); items[0].getQty(); items[1].getCost(); items[1].getName(); items[1].getQty(); items[2].getName(); items[2].getCost(); items[2].getQty(); items[3].getName(); items[3].getCost(); items[3].getQty(); Scanner scan = new Scanner(System.in); String input = scan.next(); for(int i=0; i<items.length; i++) { if(input.equals(items[i].getName())) { System.out.println("Item Found"); } else { System.out.println("Item Not Found"); } }
Item Not Found
Item Found
Item Not Found
Item Not Found
It is comparing every ite
m in the array and printing the message. How can only have it print Item Found with out the other message. Please help me with this.


LinkBack URL
About LinkBacks
Reply With Quote