我有一个非常笨重的方法来做到这一点.但是想找出一个更精简的循环方法.我想通过我的数组,并测试每个元素是否高于某个值.在这种情况下说,50.
继承人我得到了什么:
boolean found0 = false;
for (int k = 0; k < array.length ; k++) {
if (array[0] >= 50 &&
array[1] >= 50 &&
array[2] >= 50 &&
array[3] >= 50 &&
array[4] >= 50 &&
array[5] >= 50) {
found0 = true;
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用嵌套的if语句执行"do while"循环.我正在尝试比较String变量"word"的两个可能值.如果!word.equals"deeppan或thin"做某事,否则做点什么.但它不喜欢我使用或|| 比较..任何建议都会受到欢迎.
do {
word = scan.next();
if ( !word.equalsIgnoreCase( "Deeppan" || "thin" ) ) {
System.out.print("Sorry you must specify a Deeppan or thin base, try again: ");
} else {
break;
}
} while ( true );
Run Code Online (Sandbox Code Playgroud) 我遇到了这种方法的问题,我永远坚持"抱歉你必须指定一个Deeppan或瘦基地,再试一次:"即使我输入jimmy,harry,deeppan,thin,Thin ..等我输入之后deeppan或thin,我希望String存储在变量"size"中并返回
我缺少什么想法?
public String Input(){
String size;
Scanner sc = new Scanner(System.in);
System.out.println("thin or thick: ");
do {
size = scan.next();
if ( !size.equalsIgnoreCase( "thick") || !size.equalsIgnoreCase( "thin" )) {
System.out.print("Sorry you must specify a thick or thin base, try again: ");
} else {
break;
}
} while ( true );
return size;
}
Run Code Online (Sandbox Code Playgroud)