首页 > 解决方案 > 如何在 if 语句中使用字符串?

问题描述

注意:抱歉格式错误,我是堆栈溢出的新手

如果我有一段这样开头的代码,

import java.util.Scanner;
public class MyProgram
{
  public static void main(String[] args)
    {
    Scanner Input = new Scanner (System.in);
    System.out.println( "Write either yes or no." );
    String message = Input.nextLine();
并想在 if 语句中检查字符串变量“消息”的内容,我该怎么做?

我正在考虑这样的事情:

if( message == "yes" )

我的意思是检查用户在提示时写的内容,这些内容存储为消息。

标签: javastringif-statement

解决方案


推荐阅读