i had try enter other thing that not related to what i want and it will prompt the else if statement ask me enter again ..but why when i enter the correct thing it still ask me to choose again ??? why ??
here is part of my code :
public static void choose()
{
Scanner read=new Scanner(System.in);
String shape = "";
do{
System.out.println("which shape you would like to choose");
shape=read.nextLine();
if(shape.equals("rectangle"))
{
System.out.println("enter width");
width=Double.parseDouble(read.nextLine());
System.out.println("enter length");
length=Double.parseDouble(read.nextLine());
System.out.println("enter color");
String color = read.nextLine();
}
else if (shape.equals("box"))
{
System.out.println("enter width");
width=Double.parseDouble(read.nextLine());
System.out.println("enter length");
length=Double.parseDouble(read.nextLine());
System.out.println("enter height");
height=Double.parseDouble(read.nextLine());
System.out.println("enter color");
String color = read.nextLine();
}
else
{
System.out.println("please enter only rectangle and box");
}
}while((shape !="rectangle" && shape !="box"));
here my run :
which shape you would like to choose
abc
please enter only rectangle and box
which shape you would like to choose
box
enter width
9
enter length
8
enter height
8
enter color
blue
which shape you would like to choose