Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class ReadingUserInputChallenge {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int counter = 0, sum = 0;
- while (counter < 10) {
- int order = counter + 1;
- System.out.println("Enter number #" + order + ":");
- boolean isAnInt = scanner.hasNextInt();
- if (isAnInt) {
- int number = scanner.nextInt();
- counter++;
- sum += number;
- } else System.out.println("Invalid number");
- scanner.nextLine();
- }
- System.out.println("Sum = " + sum);
- scanner.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment