请JAVA高手帮忙写个程序

2024-12-26 05:48:30
推荐回答(2个)
回答1:

package exec;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class NumberCompare ...{
public static final int NUMBER = 80; // 给定一个要比较的数
public static void main(String args[]) ...{
System.out.print("Please input numbers: ");
BufferedReader io = new BufferedReader(new InputStreamReader(System.in));
try ...{
// 从键盘输入若干数
String line = io.readLine();
// 放入数组中
String[] items = line.split(" ");
int temp = 5000, x = 0, place = 0;
System.out.println("target number: 80");
// 和给定的数比较大小
for (int i = 0; i < items.length; i++) ...{
if (Integer.parseInt(items[i]) > NUMBER) ...{
x = Integer.parseInt(items[i]) - NUMBER;
} else ...{
x = NUMBER - Integer.parseInt(items[i]);
}
if (x < temp) ...{
temp = x;
place = Integer.parseInt(items[i]); } }
System.out.println("place: " + place);
io.close();
System.exit(0);
} catch (IOException e) ...{
e.printStackTrace(); } }}

居然没分!!!

回答2:

楼上的居然有心情有时间写~~~