hey all,
i was writing a program which allows users to input either a square, circle or rectangle, and depending on the input, the program would go on to get the area and perimeter of that shape.
when i run the program, it works fine till i input the shape i want, then it just goes on to say:
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:840)
at java.util.Scanner.next(Scanner.java:1461)
at java.util.Scanner.nextInt(Scanner.java:2091)
at java.util.Scanner.nextInt(Scanner.java:2050)
at Shapes.main(Shapes.java:31)
Here's the code:
import static java.lang.System.out;
import java.util.Scanner;
public class Shapes {
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;
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();
if (shape == square){
System.out.println("");
System.out.println("Please input the side length of the square.");
System.out.println("");
side1 = myScanner.nextDouble();
area = side1 * side1;
perimeter = side1 * 4;
System.out.println("The area of your square is " + area + " and the perimeter is " + perimeter + ".");
}
The ifs continue for circle and rectangle.
Pls pls pls help. i cant figure out wat is wrong
Thanks