我正在尝试制作一个程序,在其中输入形状的名称,它会告诉我它有多少面。我似乎无法让它工作。谁能解释如何做到这一点?
import java.util.Scanner;
public class Shapes {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
String shape;
System.out.print("Enter shape: ");
shape = reader.next();
if (shape == "hexagon") {
System.out.println("A hexagon has 6 sides.");
}
if (shape == "decagon"); {
System.out.println("A decagon has 10 sides.");
}
}
}