引用 | 编辑
adsl900216
2007-01-11 00:30 |
楼主
▼ |
||
x0
各位大大您们好:小弟我最近遇到一个程式的问题,就是老师最近给我们出了一道题目... 就是利用程式建立一个档案,然后在运算档案中数值的平均值和大小... 不知运算数值这程式如何写,请各位大大请帮小弟解惑...谢谢! 程式代码是"建档"的...我只写出这个 运算建立档案中的数值该怎写呢!? 请各位帮忙小弟我 感恩!!! import java.io.*; public class filein { private static String fileName; public static void main(String[] args)throws IOException { double sum=0,avg=0,max,min .. 访客只能看到部份内容,免费 加入会员 x0
|
引用 | 编辑
misboy0522
2007-01-23 21:44 |
2楼
▲ |
//我改了一下 把数值平均一下 我只是新手 希望先进改正 misboy0522
import java.io.*; public class filein { private static String fileName; public static void main(String[] args)throws IOException { double sum=0,avg=0,max,min; InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); double[] a= new double[4]; for (int i=0;i<a.length;i++) { System.out.print("请输入第"+(i+1)+"个数字:"); a[ i ] = Integer.parseInt(br.readLine()); } double m=a[0]; double o=a[1]; double p=a[2]; double q=a[3]; double r =(m+o+p+q)/4; String str1 = ""+a[0]+";"; String str2 = ""+a[1]+";"; String str3 = ""+a[2]+";"; String str4 = ""+a[3]+";"; BufferedReader buf = new BufferedReader(new InputStreamReader(System.in)); System.out.println("平均值为"+r); //misboy0522加平均值的判断 System.out.print("请存档案名称:"); fileName = buf.readLine(); FileWriter fw = new FileWriter(fileName); BufferedWriter output = new BufferedWriter(fw); output.write(str1); output.newLine(); output.write(str2); output.newLine(); output.write(str3); output.newLine(); output.write(str4); output.newLine(); output.close(); System.out.println("存档成功,请查看档案"); //misboy0522加的判断 } } /* 请输入第1个数字:66 请输入第2个数字:77 请输入第3个数字:85 请输入第4个数字:92 平均值为80.0 请存档案名称:yyy.txt 存档成功,请查看档案 Press any key to continue... */ x0 |