Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2020
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.52 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.logging.ConsoleHandler;
  3.  
  4. public class readingUserInputChallange {
  5. public static void main(String[] args) {
  6. int sum=0;
  7. int count=1;
  8. while(count<=10) {
  9. Scanner scanner=new Scanner(System.in);
  10. System.out.println("Enter the #"+count);
  11. boolean hasnextint= scanner.hasNextInt();
  12. if(hasnextint){
  13. int numbers=scanner.nextInt();
  14. sum+=numbers;
  15. count++;
  16.  
  17. } else System.out.println("Invalid numbers");
  18. //scanner.close();
  19.  
  20.  
  21.  
  22.  
  23.  
  24. }
  25.  
  26.  
  27. System.out.println("The sum is "+sum);
  28.  
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement