Scanner sc = new Scanner(System.in); String []s = {"A","S","D"}; String choice =""; for(int i=0;i<s.length;s++) { System.out.println("Enter Your Choice:") sc.next(); /* now i want to check user inserted value is only A ,D or s if other Value it should have to show error message;i have used one but it is not working */ if((!"A".equals(choice)) || (!"B".equals(choice)) || (!"C".equals(choice)) || (!"D".equals(choice) )) { System.out.println("not a ABCD"); choice =sc.next(); } }
bool isASD = Arrays.asList(s).contains(answer)
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)