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

  • Home
  • SEARCH
  • 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 7070537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:34:43+00:00 2026-05-28T05:34:43+00:00

When a user enters a whole number, the program runs smoothly, but when the

  • 0

When a user enters a whole number, the program runs smoothly, but when the user enters a number that has a decimal at the end, the program crashes.

These are the errors that I get:

    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
    at java.lang.Integer.parseInt(Integer.java:458)
    at java.lang.Integer.parseInt(Integer.java:499)
    at BMI.main(BMI.java:11)

Here is my code:

import javax.swing.*;

public class BMI {
  public static void main(String args[]) {
    int height;  // declares the height variable
    int weight;  // declares the weight variable
    String getweight;
    getweight = JOptionPane.showInputDialog(null, "Please enter your weight in Kilograms");  // asks user for their weight
    String getheight;
    getheight = JOptionPane.showInputDialog(null, "Please enter your height in Centimeters");  // asks user for their height
    weight = Integer.parseInt(getweight);  // stores their weight
    height = Integer.parseInt(getheight);  // stores their height
    double bmi;  // declares the BMI variable
    bmi = weight / Math.pow(height / 100.0, 2.0);  // calculates the BMI
    double roundbmi;  // variable to round the BMI to make it more read-able
    roundbmi = Math.round(bmi);  // rounds the BMI
    JOptionPane.showMessageDialog(null, "Your BMI is: " + roundbmi);  // displays the calculated and rounded BMI
  }
}
  • 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-28T05:34:43+00:00Added an answer on May 28, 2026 at 5:34 am

    An Integer only recognizes whole numbers. If you want to be able to capture floating point numbers, use either Float.parseFloat() or Double.parseDouble().

    To make the answer more complete, let me give you a quick example of why "4.", "4.0", and "4" are represented in two different ways. The first two are considered floating point values (since Java will just assume you mean 4.0 regardless), and how they are represented in memory depends heavily on which datatype you use to represent them – either a float or a double.

    A float represents 4.0 using the single-precision floating point standard, whereas a double would represent 4.0 using the double-precision floating point standard. An int represents the value 4 in base-2 instead (so it’d just be 22).

    Understanding how numbers are stored internally is critical and key to development, not just with Java. In general, it’s recommended to use Double since that gives the larger range of floating point numbers (and higher precision).

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

Sidebar

Related Questions

My class assignment is to write a program that has the user input a
my program records the number of bottles that 4 rooms has collected. I am
How would a go about making a program where the user enters a string,
I want to create a program that requests from the user 10 grades and
I'm trying to write a program that reads 2 numbers from the user and
I'm writing a program for a homework assignment. The program compiles and runs, but
In this problem, the user enters in two numbers. Each number represents an integer,
I need to write a program, that will ask a user to enter a
I'm beginner to c++ and writing a program that accepts user choices and acts
I'm doing a small program an addressbook that allows the user to: add contact,

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.