import java.io.*;
class hargabuncis
{
public static void main (String [] args)
{
String x;
int harga=0,jumlah=0,n=0;
try
{
FileInputStream fstream= new FileInputStream ("c:/hargabuncis.txt");
DataInputStream datainput = new DataInputStream(fstream);
while (datainput.available()!=0)
{
x=datainput.readLine();
harga=Integer.parseInt(x);
n=n+1;
jumlah=jumlah+harga;
System.out.println("harga buncis hari ke "+n+" "+harga);
}
datainput.close();
}
catch (Exception e)
{
System.out.println("File Input Error");
}
double rata2=jumlah/n;
System.out.println("harga buncis rata-rata "+rata2);
}
}
Tidak ada komentar:
Posting Komentar