wus t java5次上机必备 联系客服

发布时间 : 星期六 文章wus t java5次上机必备更新完毕开始阅读c2e2d087fbb069dc5022aaea998fcc22bdd14358

1)实验代码 实验一: import java.util.*; public class Test { public static void main(String[] args) { int n = 10; 主 int[] array = getIntegers(new Scanner(System.in), n); 要实 Arrays.sort(array); 验 System.out.printf(\记 System.out.printf(\录 及 } 个 人 小 private static int[] getIntegers(Scanner scanner, int count) { 结 int[] array = new int[count]; while (true) { (包 System.out.printf(\括 try { 部分 for (int i = 0; i < 10; ++i) { 实验 array[i] = Integer.parseInt(scanner.next()); 源程 } 序 return array; 、调 } catch (NumberFormatException e) { 试结 System.out.println(\果 } 及实 } 验结 } 果分} 析 等)实验二: import java.io.*; public class CopyFile { public static void main ( String args[] ) { } static String deleteComments(String s) { if( null == s ) return s; String infname = \String outfname = \try { } catch(FileNotFoundException e1) { } catch(IOException e2) { } e2.printStackTrace(); System.err.println(\File fin = new File(infname); File fout = new File(outfname); BufferedReader in = new BufferedReader(new FileReader(fin)); PrintWriter out = new PrintWriter(new FileWriter(fout)); String s = in.readLine(); while( s != null ) { } in.close(); out.close(); 主要实验记录及个人小结 (包括部分实验源程序、调试结果及实验结果分析等) s = deleteComments(s); if( s.length()!=0 ) out.println(s); s = in.readLine(); int pos = s.indexOf(\if( pos < 0 ) return s; return s.substring(0, pos); } } 2)实验结果: 实验一: 主要 实 验 记 录 及 个 人 实验二: 小 结 (包括部分实验源程 序 、3)程序调试过程中存在问题的思考 调试程序调试过程中存在问题:在编译时总是出现了子类没有实现父类的方法 结果解决办法:发现把getPay误写成了getpay ,在每个子类中的getPay方法前也要加及public,不然也会出现没有实现父类的方法的提示。 实验 结果分 析等) 二、思考题 1) 程序清单 思考题一: import java.io.*; public class Stdfile { static int max(int a[], int n) //最高分 主要实验记录及个人小结(包括部分实验源程序、调试结果及实验结果分析等) { int temp = a[0]; //临时变量 for(int i = 1; i < n; i++) if(a[i] > temp) temp = a[i]; return temp; } static int min(int a[], int n) //最低分 { int temp = a[0]; for(int i = 1; i < n; i++) if(a[i] < temp) temp = a[i]; return temp; } static int average(int a[], int n) // 求平均值 { int temp = 0; for(int i = 0; i < n; i++) temp += a[i]; return temp/n; } public static void main(String args[]){ try{ File fin = new File(\ File fout = new File(\ BufferedReader in = new BufferedReader(new FileReader(fin)); //读文件Std1.txt PrintWriter out = new PrintWriter(new FileWriter(fout)); //写到Std2.txt int[] scores = new int[30]; int flag = 0; int num = 0; String s = in.readLine(); flag++; while(s != null){ if(flag%2==0){ scores[num] = Integer.valueOf(s); num++; } s = in.readLine(); flag++; } int maxValue = max(scores, 30); int minValue = min(scores, 30); int averageValue = average(scores, 30); System.out.println(\所有学生的最高分是:\