各位看看有没有改进的可能
程序代码:
package exception; import javax.swing.JOptionPane; public class Calc3 { public static void main(String[] args){ double[] arr = new double[10]; double temp = 0; double average = 0; double sum = 0; for (int i=0; i<arr.length; i++){ try{ String str = JOptionPane.showInputDialog(null, "请输入一个数"); double j = Double.parseDouble(str); arr[i] = j; } catch (NumberFormatException ex){ JOptionPane.showMessageDialog(null, "对不起,你输入的格式有误,请重新输入!!!"); String str1 = JOptionPane.showInputDialog(null, "请再次输入一个数"); double k = Double.parseDouble(str1); arr[i] = k; } } for (double e: arr){ System.out.print(e +" "); sum = sum + e; } System.out.println(); average = sum / 10; System.out.println("平均值 = " +average); for (int m=0; m<arr.length-1; m++){ for (int n=0; n<arr.length-1-m; n++){ if (arr[n] > arr[n+1]){ temp = arr[n]; arr[n] = arr[n+1]; arr[n+1] = temp; } } } System.out.println("最大值 = " +arr[arr.length-1]+ "最小值 = " +arr[0]); } }用JOptionPane输入10个double数值,分别是10个评委的亮分。如果输入的内容无法转换成为double,则重新出现输入框,并且输入框上面显示:对不起,您输入的格式有误,请您重新输入。最后显示最高分,最低分,平均分。