Advertisement
Guest User

Untitled

a guest
Sep 17th, 2014
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.75 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.            
  18.  
  19.             if (luku == -1) {
  20.                 System.out.println("Kiitos ja näkemiin!");
  21.                 System.out.println("Summa: " + summa);
  22.                 System.out.println("Lukuja: " + toistojenMaara);
  23.                 break;
  24.             }
  25.            
  26.             summa = summa + luku;
  27.             toistojenMaara++;
  28.  
  29.         }
  30.  
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement