Advertisement
Yusufmm

UTS_No_3_While

Apr 10th, 2015
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.70 KB | None | 0 0
  1. package uts_semester2;
  2.  
  3. import java.util.Scanner;
  4.  
  5. /**
  6.  * @author Yusuf
  7.  * Soal no 3 while
  8.  */
  9. public class No_3_While {
  10.     public static void main(String[] args) {
  11.         Scanner sc = new Scanner(System.in);
  12.        
  13.         int n, x;
  14.         int i = 0;
  15.         double total = 0;
  16.         double rataRata;
  17.        
  18.         System.out.print("Masukkan jumlah data : ");
  19.         n = sc.nextInt();
  20.        
  21.         while (i < n) {
  22.             i++;
  23.             System.out.print("Masukkan data ke " + i + " : ");
  24.             x = sc.nextInt();
  25.             total += x;
  26.         }
  27.        
  28.         rataRata = total / n;
  29.        
  30.         System.out.println("Rata-rata = " + rataRata);
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement