如何编写伪代码来声明和填充包含10个元素的数组。我需要使用一个循环来填充数组,并搜索数组中的值20。如果找到了该值,则显示一条消息,显示该值所在的下标。该值可能不止一次出现。如果找不到该值,则显示一条适当的消息。
发布于 2022-07-06 08:18:58
int[] array = {2, 5, 8, 20, 13, 5, 20, 3, 6, 7};
boolean isValueFound = false;
for(int i=0; i<array.length; i++) {
if(array[i] == 20) {
system.out.println("Value found at position " + i+1);
isValueFound = true;
}
}
if(!isValueFound) {
system.out.println("Value not found");
}
https://stackoverflow.com/questions/72886790
复制相似问题