Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: user input mismatch problem

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    17
    My Mood
    Confused
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default user input mismatch problem

    hey all,

    i have a program which asks the user to input the shape they want to know the area and perimeter of.
    i have all the code done but i don't know how to define the variable so that it can be represented by the letters the user inputs.
    here is the code it that doesn't make sense

    public static void main(String[] args) {
    Scanner myScanner = new Scanner(System.in);
    double diameter = 0;
    double circumference = 0;
    double radius = 0;
    double area = 0;
    double perimeter = 0;
    double side1 = 0;
    double side2 = 0;
    int shape = 0; // so far i have defined them as integers, which someone said won't work//
    int square = 0;
    int rectangle = 0;
    int circle = 0;
    System.out.println("This program finds the area and perimeter of either a square, rectangle or circle.");
    System.out.println("");
    System.out.println("Firstly, input what shape you want to find the perimeter and area of.");
    System.out.println("");
    shape = myScanner.nextInt(); //here is where the error occurs and i get a mismatch input exception//

    what do i have to change so that i dont get the mismatch

    thanks


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: user input mismatch problem

    what do i have to change so that i dont get the mismatch
    What are you entering at the console? The nextInt method expects a whole number.
    You can either change what you enter to be a whole number
    or you can change the program so it will read a String. See the API doc for the Scanner class for a choice of methods to use.

Similar Threads

  1. Action Listener?user input problem
    By gpelefty90 in forum AWT / Java Swing
    Replies: 1
    Last Post: November 2nd, 2011, 05:17 AM
  2. Valid user input
    By ChristopherLowe in forum Java Programming Tutorials
    Replies: 1
    Last Post: June 21st, 2011, 04:53 PM
  3. Valid user input
    By ChristopherLowe in forum Java Code Snippets and Tutorials
    Replies: 1
    Last Post: June 21st, 2011, 04:53 PM
  4. User Input File Name
    By PineAppleKing in forum Java Theory & Questions
    Replies: 12
    Last Post: June 3rd, 2011, 10:23 AM
  5. [SOLVED] allow a new input, dicarding the last mismatch input without terminating the program
    By voltaire in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 9th, 2010, 04:44 AM