本文介绍了如何检查用户插入的值是对还是错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 亲爱的, i有关于我的java代码的问题。我的代码是 扫描仪sc = 新扫描仪(System.in); 字符串 [] s = { A , S, D}; 字符串 choice = ; for ( int i = 0; i< s.length; s ++) { System.out.println( 输入您的选择:) sc.next(); / * 现在我想检查用户插入的值是否仅为A,D或s,如果是其他值则应该必须显示错误消息;我已经使用了一个但它不起作用* / if ((! .equals(choice))||(! B .equals(choice))||(! C .equals(choice))||(! D .equals(选项))) { System.out.println( 不是ABCD); choice = sc.next(); } } 解决方案 bool isASD = Arrays.asList(s).contains(answer) Dear all,i have problem about my java code.here is my code 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) 这篇关于如何检查用户插入的值是对还是错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-25 09:04