Assume that the following variables have been properly declared and initialized.

1. a boolean variable named rsvp
2. an int variable named selection, where 1 represents "beef", 2 represents "chicken", 3 represents "pasta", and all other values represent "fish"
3. a String variable named option1
4. a String variable named option2

Write a code segment that will print true if the strings option1 and option2 contain the same values and will print false otherwise

Respuesta :

ijeggs

Answer:

       if (option1.equals(option2)){

           rsvp = true;

       }

       System.out.println(rsvp);

A full program is given in the explanation section

Explanation:

import java.util.Scanner;

public class Option {

   public static void main(String[] args) {

       boolean rsvp = false;

       int selection;

       String option1,option2;

       Scanner in = new Scanner(System.in);

       option1 = in.next();

       option2 = in.next();

       if (option1.equals(option2)){

           rsvp = true;

       }

       System.out.println(rsvp);

   }

}

Boolean variables are variables that can only take either true or false.

The required code segment is:

rsvp = false;

if (option1.equals(option2)){

rsvp = true; }

System.out.print(rsvp);

The flow of the above code segment is as follows:

  • The first line initializes rsvp to false
  • The next line is a conditional statement that checks if option1 and option2 holds the same value
  • The third line updates rsvp to true, if the condition is true
  • The last line prints rsvp (i.e. true or false)

Read more about boolean expressions at:

https://brainly.com/question/18539409

ACCESS MORE