If the user key in 4 I wish to pop up a message to inform the user that is no data found for user id "4" in the array list.
But when the user key in 4 there is 3 no data found appear.
User usr1 = new User(1,"Ken", 55.5, 26, Arrays.asList("0140392812", "0123456789"));
User usr2 = new User(2, "Mark", 54.7, 33, Arrays.asList("0129876543"));
User usr3 = new User(3, "Ong", 62.3, 34, Arrays.asList("06123456", "0987654322", "01798654321"));
ArrayList<User> ulist = new ArrayList<User>();
ulist.add(usr1);
ulist.add(usr2);
ulist.add(usr3);
String answer ="";
do{
Scanner scan = new Scanner(System.in);
System.out.println("Please Enter user ID");
int userid = scan.nextInt();
for(User uid: ulist){
if(userid == uid.getUID()){
System.out.println(uid.getUID() +", " + uid.getName() +", " + uid.getAge() +" years old, " + uid.getWeight() +"kg");
}else{
System.out.println("no data found");
}
}
System.out.println("Continue(Y/N)");
answer = scan.next();
}while(answer.equalsIgnoreCase("y"));
current result:
no data found
no data found
no data found
Result that i wish:
no data found