在for循环中查找值的最大值/最小值 [英] Find the Max/Min of values within a for loop
问题描述
System.out.print(您要输入多少个数字?);
int totalNumbers = console.nextInt();
int minMax = 0;
for(int i = 1; i <= totalNumbers; i ++){
System.out.print(Number+ i +:);
int inputNumbers = console.nextInt();
}
System.out.println();
int最小= Math.min(minMax);
System.out.println(Smallest =+ smallest);
int maximum = Math.max(minMax);
System.out.println(Largest =+ largest);
我不需要改变代码就可以让我走上正轨。谢谢!
您正在运行循环 选项: 我不是在写任何解决方案,因为我希望您自己尝试。 I've searched for answers to this specific question, but haven't been able to find anything. I need to find the maximum and minimum of the input numbers but the values I need are inside the for loop and I can't figure out how to use them outside of it. I don't need changed code just something that will get me on the right track.Thank you! Can you notice the problem with the following loop? You are running the loop Now you have few options: I am not writing any solution as I want you to try it yourself. 这篇关于在for循环中查找值的最大值/最小值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
<$ p (int i = 1; i <= totalNumbers; i ++){
System.out.print(Number+ i +:); $ p>
int inputNumbers = console.nextInt();
$ b totalNumbers
次,每次创建一个名为 inputNumbers
的新的 int
并存储从控制台接收的值。另外你在哪里改变 minMax
的值?另外 Math.min(或者max)
并不需要单个参数,甚至不需要编译。
$ b
System.out.print("How many numbers do you want to input?");
int totalNumbers = console.nextInt();
int minMax = 0;
for(int i = 1; i <= totalNumbers; i++){
System.out.print("Number " + i + ": ");
int inputNumbers = console.nextInt();
}
System.out.println();
int smallest = Math.min(minMax);
System.out.println("Smallest = " + smallest);
int largest = Math.max(minMax);
System.out.println("Largest = " + largest);
for(int i = 1; i <= totalNumbers; i++){
System.out.print("Number " + i + ": ");
int inputNumbers = console.nextInt();
}
totalNumbers
times and every time you create a new int
with name inputNumbers
and store the value received from console. Also where are you changing the value of minMax
? Also Math.min(or max)
does not take single paramtere and wont even compile.