Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8827183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:18:54+00:00 2026-06-14T07:18:54+00:00

I have been trying to stop the exceptions but I cannot figure out how.

  • 0

I have been trying to stop the exceptions but I cannot figure out how.
I tried parseInt, java.util.NormalExceptionMismatch etc.

Does anyone have any insight how to fix this problem? Formatting is a bit off due to copy and paste.

do
{
   System.out.print(
           "How many integers shall we compare? (Enter a positive integer):");
   select = intFind.nextInt();
   if (!intFind.hasNextInt()) 
       intFind.next();
       {
           // Display the following text in the event of an invalid input
           System.out.println("Invalid input!");
       }
}while(select < 0)

Other methods I have tried :

 do
    {
       System.out.print(
                   "How many integers shall we compare? (Enter a positive integer):");
       select = intFind.nextInt();
       {
            try{
                   select = intFind.nextInt();
               }catch (java.util.InputMismatchException e)
            {
               // Display the following text in the event of an invalid input
               System.out.println("Invalid input!");
               return;
            }
       }
    }while(select < 0)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T07:18:55+00:00Added an answer on June 14, 2026 at 7:18 am

    It seems to me that you want to skip everything until you get an integer. This code here skips any input except an integer.

    As long as there is no integer available (while (!in.hasNextInt())) discard the available input (in.next). When integer is available – read it (int num = in.nextInt();)

    public class Main {
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            while (!in.hasNextInt()) {
                in.next();
            }
            int num = in.nextInt();
            System.out.println("Thank you for choosing " + num + " today.");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem that I have been trying to figure out for hours
I've been trying to figure out how I could temporary stop the timer on
I have been trying to make an init script using start-stop-daemon. I am stuck
I have been trying to resolve this but just couldn't get it right. I
I have been trying out the spring-security-facebook plugin and so far its been smooth.
I have been trying pretty much everything to get my live wallpaper to stop
I have been trying to understand why I cannot access these links from my
I'm trying to figure out a way to trap all exceptions on a site
I have been trying to stop my background image from expanding my body's height,
Have been trying to encrypt an xml file to a string so that I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.