Advertisement
Guest User

Untitled

a guest
Jan 26th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class LukujenKeskiarvo {
  4.  
  5. public static void main(String[] args) {
  6. Scanner lukija = new Scanner(System.in);
  7.  
  8. int summa = 0;
  9. int lukuja = 0;
  10.  
  11. while (true) {
  12. System.out.println("Syötä luku");
  13. int luku = Integer.valueOf(lukija.nextLine());
  14.  
  15. if (luku == 0) {
  16. break;
  17.  
  18. } else {
  19. lukuja = lukuja + 1;
  20. summa = summa + luku;
  21. }
  22.  
  23.  
  24. }
  25. double keskiarvo = summa / lukuja;
  26. System.out.println("Lukujen keskiarvo " + keskiarvo);
  27. }
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement