1

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.

braini
  • 29
  • 4
  • Use `.equals` method instead of `==` operator. here is [why](https://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java) – Omkar76 Jan 03 '21 at 04:14

0 Answers0