Advertisement
Guest User

Untitled

a guest
Sep 17th, 2014
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.04 KB | None | 0 0
  1.  
  2. import java.util.Scanner;
  3.  
  4. public class SilmukatLopetusMuistaminen {
  5.  
  6.     public static void main(String[] args) {
  7.  
  8.         Scanner lukija = new Scanner(System.in);
  9.  
  10.         int summa = 0;
  11.         int toistojenMaara = 0;
  12.  
  13.         while (true) {
  14.             System.out.println("Syötä luvut: ");
  15.             int luku = Integer.parseInt(lukija.nextLine());
  16.  
  17.             int parilliset = 0;
  18.             int parittomat = 0;
  19.  
  20.             if (luku % 2 = 0) {
  21.                 parilliset++;
  22.             } else if (luku % 2 != 0) {
  23.                 parittomat++;
  24.             } else if (luku == -1) {
  25.                 System.out.println("Kiitos ja näkemiin!");
  26.                 System.out.println("Summa: " + summa);
  27.                 System.out.println("Lukuja: " + toistojenMaara);
  28.  
  29.                 double keskiArvo = (double) summa / toistojenMaara;
  30.  
  31.                 System.out.println("Keskiarvo: " + keskiArvo);
  32.                 break;
  33.             }
  34.  
  35.             summa = summa + luku;
  36.             toistojenMaara++;
  37.  
  38.         }
  39.  
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement