Java 输入don';不匹配
我对代码中的输入有问题。在这个程序中,我想创建一个菜单,允许我们在其中放置形状。在第一个选项中,当我写正方形、圆形或矩形时,程序应该问我边、半径或高度和宽度。然而,当我编写这种形状时,程序会返回到菜单,因为什么也并没有发生。你能帮忙吗Java 输入don';不匹配,java,java.util.scanner,Java,Java.util.scanner,我对代码中的输入有问题。在这个程序中,我想创建一个菜单,允许我们在其中放置形状。在第一个选项中,当我写正方形、圆形或矩形时,程序应该问我边、半径或高度和宽度。然而,当我编写这种形状时,程序会返回到菜单,因为什么也并没有发生。你能帮忙吗 import java.util.*; public class test { public static void main(String[] args) { Scanner scan = new Scan
import java.util.*;
public class test
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
Scanner scan2 = new Scanner(System.in);
String kindofshape;
int choice, radius, width, height, side;
do
{
System.out.println("(1) Add a shape to the list");
System.out.println("(2) Get the total area of the shapes");
System.out.println("(3) Show information of the shapes");
System.out.println("(4) Quit");
System.out.println("Choice : ");
choice = scan.nextInt();
if (choice == 1)
{
System.out.println("enter the type of the shape");
kindofshape = scan2.nextLine();
if(kindofshape == "circle")
{
System.out.println("enter the radius");
radius = scan.nextInt();
}
if(kindofshape == "rectangle")
{
System.out.println("enter the width");
width = scan.nextInt();
System.out.println("enter the height");
height = scan.nextInt();
}
if(kindofshape == "square")
{
System.out.println("enter the width");
side = scan.nextInt();
}
}
}while(choice != 4);
}
}
这是Java。您应该将字符串与
.equals()
进行比较,而不是与=
进行比较。
如果将字符串与==
进行比较,则会比较实例而不是字符串值。
请使用
开关来对抗如果还有结构。这是Java。您应该将字符串与.equals()
进行比较,而不是与=
进行比较。
如果将字符串与==
进行比较,则会比较实例而不是字符串值。
请使用开关来对抗如果还有结构。这是Java。您应该将字符串与.equals()
进行比较,而不是与=
进行比较。
如果将字符串与==
进行比较,则会比较实例而不是字符串值。
请使用开关来对抗如果还有结构。这是Java。您应该将字符串与.equals()
进行比较,而不是与=
进行比较。
如果将字符串与==
进行比较,则会比较实例而不是字符串值。
请使用切换来对抗如果还有结构。==“圆圈”
==“圆圈”
==“圆圈”
==“圆圈”
我改变了,它工作了。谢谢。我换了衣服,效果很好。谢谢。我换了衣服,效果很好。谢谢。我换了衣服,效果很好。谢谢