满意答案
sw8126431
2014.07.02
采纳率:42% 等级:9
已帮助:1262人
package com.cityhome.logfile;import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;public class Test { /**
* @param args
*/
@SuppressWarnings("unchecked")
public static void main(String[] args) {
int[] num = new int[4];// 保存输入的值
int i = 0;
do {// 此循环用于接受用户输入的值
System.out.println("请输入第" + (i + 1) + "个数:");
InputStreamReader reader = new InputStreamReader(System.in);
try {
String str = (new BufferedReader(reader)).readLine();
if (str.matches("\\d*")) {
num[i] = Integer.valueOf(str).intValue();
} else {
System.out.println("请输入数字");
i--;
continue;
}
} catch (IOException e) {
e.printStackTrace();
}
i++;
} while (i < 4); int result = 0;// 保存最大的结果 for (int j = 0; j < num.length; j++) {// 此循环用于判断输入的值
if (result < num[j]) {
result = num[j];
}
} System.out.println("您输入的最大数为:" + result);
}
}
测试结果为:
04分享举报