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 6572765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:02:52+00:00 2026-05-25T15:02:52+00:00

Why I have got inputMismatchException? When the inputs are only integer the result will

  • 0

Why I have got inputMismatchException?
When the inputs are only integer the result will be good, But when I use double inputs the compiler throw an inputMismatchException.

public static void main(String[] args) {
    // TODO Auto-generated method stub
    // Help by Sahil Muthoo
    System.out.println("Enter the radius and length of a cylinder:");
    Scanner sc = new Scanner(System.in);
    Pattern newlineOrSpace = Pattern.compile(System.getProperty("line.separator") + "|\\s");
    sc.useDelimiter(newlineOrSpace);
    double radius=sc.nextDouble();
    double length=sc.nextDouble();
    double area= radius*radius*Math.PI;
    double volume=area*length;
    System.out.println("The area is " + area);
    System.out.println("The volume is " + volume);
}

Forexample inputs: 3 5 it will be good.

Forexample inputs: 3.3 5 it will throw inputMismatchException

  • 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-05-25T15:02:52+00:00Added an answer on May 25, 2026 at 3:02 pm

    You seem to work with the wrong locale. If you do not explicitly tell the JVM which locale to use to interpret the floating point inputs, it will use your system’s (JVM) default locale.

    Explicitly set the locale to US format:

    public static void main(String[] args) {
        Locale.setDefaultLocale(Locale.US);
        ...
    

    I reproduced the problem as follows:

    1. set default locale to GERMANY (decimal delimiter is comma), input 3,5 works, but 3.5 does not.
    2. set default locale to US (decimal delimiter is point), input 3.5 works, but 3,5 does not.

    As this is homework you should go back to your prof and ask for clarification on multi-language requirements 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have got a setup where users can either use a web-based form or
I have got a abstract class which is implementing 3 interfaces. public abstract class
I have got a custom event set up (see below), but when I listen
I have got a problem with the zend navigation. I use the zend navigation,
I have got mongo db using only one collection and consuming average cpu usage
I have got all categories sorted as in admin in localhost but in web
I have got a simple but strange problem. I am unable to set size
Have got an NSString *str = @12345.6789 and want to find out if there
We have got a custom MembershipProvider in ASP.NET . Now there are 2 possible
We have got loads of options for php + MySQL + Apache combo... Which

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.