Thursday, 15 September 2011

java - Do not print "not found" when something is found -


I am trying to do this project and for some reason I have a problem that I can solve for my life can not do .

  Public static zero printlist (string n) {for (INTI I = 0; I & lt; roomlist.size (); i ++) {if (roomlist.get (i) Name.equals N)} {System.out.println ("room name:" + room-list.gate (i) .name + "state:" + + roomlag.get (i) .state); System.out.println ("Description:" + roomlist.get (i) .desc); System.out.println ("Biology in the Cell:" + RoomList.Gate (i) .Fred ()); If (roomlist.get (i) .north! = Null) {System.out.println ("Northern Neighborhood:" + roomlist.get (i) .north.name); } If (roomlist.get (i) .south! = Null) {System.out.println ("South Neighbor:" + roomlist.get (i) .south.name); } If (roomlist.get (i). Last! = Null) {System.out.println ("Former Neighbors:" + roomlist.get (i) .east.name); } If (roomlist.get (i) .west! = Null) {System.out.println ("West Neighborhood:" + roomlist.get (i) .west.name); }}} System.out.println ("Room" + n + "does not exist!"); }  

Even if it finds the cell object in ArrayList, it still prints "cell" + n + "does not exist"! I need that only if the print did not get in ArrayList

The reason for this is because Not Found The message is the final description of your method. You should return to the immediate method as if you got your element and you print your desired messages.

For example, each room has a unique name to handle:

  .. (roomlist.get (i) .name.equals (n)) { ... if (roomlist.get (i) .west! = Null) {System.out.println ("west neighbor:" + find room list (i) .west.name); } Return; } ...  

No comments:

Post a Comment