引用 | 編輯
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 |