Source Code
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class RataRata {
public static void main(String args[]) {
final int JUMLAH_DATA = 10;
int[] data = new int[JUMLAH_DATA];
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
for(int i = 0; i < JUMLAH_DATA; i++) {
System.out.print("data ke - " + i + " : ");
try {
String dtStr = bf.readLine();
data[i] = Integer.parseInt(dtStr);
} catch(IOException e) {
System.out.print(e);
}
}
System.out.println("----------------------------------------------");
System.out.print("Data acak : ");
int jumlah = 0;
for(int i = 0; i < JUMLAH_DATA; i++) {
System.out.print(data[i] + ", ");
jumlah += data[i];
}
float rata2 = jumlah / JUMLAH_DATA;
System.out.println("\n---------------------------------------------");
System.out.println("Rata - rata = " + rata2);
}
}
Sebelum mengcopy paste source code yang ada diatas. Anda harus mempunyai master pemrograman Java, seperti: Java SE, JCreator, dll. Di sini saya memakai JCreator.
Silahkan download di sini.
Setelah itu Anda tinggal copy paste source code yang ada di atas.
Selamat Mencoba!
Menghitung Nilai Rata-rata
Original by : Kang Agunk.
Labels:
Array,
Source Code
Subscribe to:
Post Comments (Atom)
Comments :
Post a Comment