Advertisement
TsetsoP

While Упр 1

Nov 5th, 2020
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.44 KB | None | 0 0
  1. package uktc;
  2. import java.util.Scanner;
  3. public class whileee {
  4.  
  5.     public static void main(String[] args) {
  6.        
  7. Scanner scan = new Scanner(System.in);
  8. System.out.println("Enter number for sum: ");
  9. int n = scan.nextInt();
  10. int i = 1;
  11. int sum = 0;
  12. while(i<=n){
  13.      System.out.println("Enter number:" + i);
  14.      i++;
  15.      int currentNumber = scan.nextInt();
  16.  
  17.      sum = sum + currentNumber;
  18. }
  19.  
  20. System.out.println("Sum: " + sum);
  21.  
  22.  
  23.     }
  24.  
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement