Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package uts_semester2;
- import java.util.Scanner;
- /**
- * @author Yusuf
- * Soal no 4 for
- */
- public class No_4_For {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int n, x;
- double total = 0;
- double rataRata;
- System.out.print("Masukkan jumlah data : ");
- n = sc.nextInt();
- for (int i = 1; i <= n; i++) {
- System.out.print("Masukkan data ke " + i + " : ");
- x = sc.nextInt();
- total += x;
- }
- rataRata = total / n;
- System.out.println("Rata-rata = " + rataRata);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement