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 3 while
- */
- public class No_3_While {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int n, x;
- int i = 0;
- double total = 0;
- double rataRata;
- System.out.print("Masukkan jumlah data : ");
- n = sc.nextInt();
- while (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