我对编程/java很陌生,今晚有一项短期任务要完成,我搞不懂。只是需要往正确的方向走。这是我需要的东西。
编写一个方法methodOne(),它返回一个浮点的值。它有两个参数。第一个参数是整数数组,第二个参数是字符串数组。
methodOne()按顺序检查字符串数组的每个元素的值。如果一个元素不是null,那么整数数组中的对应元素将用作函数调用methodTwo()中的参数。methodTwo()检查参数的值。如果它大于零,那么methodTwo()返回true,否则返回false。
在methodTwo()返回到methodOne()时,methodOne()检查该值,如果它等于true,则继续,否则返回-1.0。
谢谢
发布于 2020-02-11 00:16:06
这段代码应该能让你开始。基本上,您在遍历数组时保留一个索引。基于这个问题,我假设字符串和整数数组都有相同的大小。
public Integer methodOne(int[] numberArray, String[] stringArray){
boolean check = false;
for(int i = 0; i < stringArray.length; i++){
if(!stringArray[i].equals(null)) {
check = methodTwo(numberArray[i]);
}
}
if(check == false){
return -1;
}
else{
return 0; //"RETURN SOMETHING ELSE HERE
}
}
public boolean methodTwo(int number){
return number > 0;
}如果数字大于0,则“返回编号> 0”将返回true,否则返回false
https://stackoverflow.com/questions/60160096
复制相似问题