0
import java.util.Scanner; 

public class shirt
{
  public static void main(String[] args)  
   {    
   Scanner userinput = new Scanner (System.in);

String nbshirts;

System.out.println("How many shirts do you have");

nshirts = userinput.next();

if (nbshirts.equals("five"))
{

System.out.println("Just like me !");
}

else 
{
   System.out.println("We don't have the same number of shirt");
} 
  }
  }

您好,我想要的是 if/else 语句验证输入是否为 5 或 5 的可能性。我不知道要添加什么/如何继续创建一个对话框,其中 5 和 5 都是接受为真值。希望你能帮我 !:)

4

1 回答 1

1

如果您正在检查的变量是nbshirts那么这应该工作:

if(nbshirts.equals("five") || "5".equals(nbshirts))

希望这可以帮助!

于 2015-01-19T14:40:56.360 回答