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

Re: user input mismatch problem

Quote:

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.