Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class SilmukatLopetusMuistaminen {
- public static void main(String[] args) {
- Scanner lukija = new Scanner(System.in);
- int summa = 0;
- int toistojenMaara = 0;
- while (true) {
- System.out.println("Syötä luvut: ");
- int luku = Integer.parseInt(lukija.nextLine());
- int parilliset = 0;
- int parittomat = 0;
- if (luku % 2 = 0) {
- parilliset++;
- } else if (luku % 2 != 0) {
- parittomat++;
- } else if (luku == -1) {
- System.out.println("Kiitos ja näkemiin!");
- System.out.println("Summa: " + summa);
- System.out.println("Lukuja: " + toistojenMaara);
- double keskiArvo = (double) summa / toistojenMaara;
- System.out.println("Keskiarvo: " + keskiArvo);
- break;
- }
- summa = summa + luku;
- toistojenMaara++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement