java代码做repeat次运算,从键盘输入几个数,比最值
总结:今天这个题目有点灵活,因为它不但要求输出结果,还要进行几次相同的输入,不退出循环
import java.util.Scanner;
//从键盘一次输入更多的数,然后把每一次的数进行---可比较,或输出
public class ertyw {
public static void main(String[] args) {
Scanner c = new Scanner(System.in);
System.out.println("输入m次");
int x = c.nextInt();
for (int i = 0; i < x; i++) {// 这里的x表示输入几次。x就是x次
System.out.println("你输入的数据是;");
int y = c.nextInt();
int s = c.nextInt();
int z = c.nextInt();
int w = c.nextInt();
int max = y;
if (max < z) {
max = z;
}
if (max < w) {
max = w;
}
if (max < s) {
max = s;
}
System.out.println("最大值是" + max);
}
}
}
//输入m次
4
你输入的数据是;
32 21 2 876
最大值是876
你输入的数据是;
3 43 444 2
最大值是444
你输入的数据是;
3545 5 84 43
最大值是3545
你输入的数据是;
42 74 77 32
最大值是77
浙公网安备 33010602011771号