This problem is inputting 10 numbers, and printing th My solution is working except it runs forever when I input anything other than an int. Can someon tell me whatI've done wrong?
package com.company; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int count = 1; int sum = 0; while (count<=10) { System.out.println("Enter number #"+count); boolean hasNextInt = scanner.hasNextInt(); if (hasNextInt){ int number = scanner.nextInt(); count++; sum +=number; } else { System.out.println("Invalid Input"); continue; } scanner.nextLine(); }System.out.println("the sum of these numbers is "+sum); scanner.close(); } }