Coding sederhana untuk menghitung
rata-rata deret bilangan menggunakan BufferedReader. Misal bilangan 4,5,4 maka
akan muncul rata-ratanya 4,33333
package
deret_bilangan;
import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;
public class rata_rata_bilangan {
public static void main(String []args){
try {
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
int deret = 0;
double r = 0;
double t = 0;
double i = 0;
double a = 0;
System.out.println("Masukkan Jumlah Deret : ");
deret = Integer.parseInt(input.readLine());
for (int x = 0; x < deret; x++) {
System.out.println("Masukkan Angka:");
a = Integer.parseInt(input.readLine());
t = t + a ;
i = i + 1;
r = t / i ;
}
System.out.println("Rata-Rata:" + r);
} catch (IOException ex) {
Logger.getLogger(rata_rata_bilangan.class.getName()).log(Level.SEVERE, null, ex);
}
import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;
public class rata_rata_bilangan {
public static void main(String []args){
try {
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
int deret = 0;
double r = 0;
double t = 0;
double i = 0;
double a = 0;
System.out.println("Masukkan Jumlah Deret : ");
deret = Integer.parseInt(input.readLine());
for (int x = 0; x < deret; x++) {
System.out.println("Masukkan Angka:");
a = Integer.parseInt(input.readLine());
t = t + a ;
i = i + 1;
r = t / i ;
}
System.out.println("Rata-Rata:" + r);
} catch (IOException ex) {
Logger.getLogger(rata_rata_bilangan.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
0 komentar:
Posting Komentar