samedi 2 janvier 2021

How do I use Strings in if statements? [duplicate]

note: sorry about the bad formatting, I'm new to stack overflow

If I had a piece of code that started like this,

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();
and wanted to check the String variable "message"'s contents in an if statements, how would I do that?

I am thinking about something like this:

if( message == "yes" )

By this, I mean checking what the user wrote when prompted to, which is stored as message.

Aucun commentaire:

Enregistrer un commentaire