Knowee
Questions
Features
Study Tools

Which of the following will loop until the user enters a value for String for str2 that matches str1?  (Mark ALL that apply)Scanner input = new Scanner(System.in);String str1 = input.nextLine();String str2 = input.nextLine();while ( CONDITION ) { str2 = input.nextLine();}Group of answer choicesstr2 != str1str1 != str2!str2.equals(str1)!str1.equals(str2)

Question

Which of the following will loop until the user enters a value for String for str2 that matches str1?  (Mark ALL that apply)Scanner input = new Scanner(System.in);String str1 = input.nextLine();String str2 = input.nextLine();while ( CONDITION ) { str2 = input.nextLine();}Group of answer choicesstr2 != str1str1 != str2!str2.equals(str1)!str1.equals(str2)

🧐 Not the exact question you are looking for?Go ask a question

Solution

The correct conditions that will loop until the user enters a value for String str2 that matches str1 are:

!str2.equals(str1) !str1.equals(str2)

These conditions check if str2 is not equal to str1. The loop will continue until str2 equals str1. The "!=" operator is not used for string comparison in Java, so the first two options are incorrect.

Similar Questions

Fill the below code to compare two strings and print "yes" if they are same else print "no".Don't consider the case. Example, if the strings are  "Good" and "good" the output  should be "yes".Code :                Scanner sc=new Scanner(System.in); String s1=sc.next(); String s2=sc.next(); if()                         System.out.println("yes");                else                  System.out.println("no");

Scanner nextLine() _____________   the next newline (\n).Group of answer choicesstops beforereads

The next() method of java.util.Scanner class returns a string that contains the rest characters of the current line, e.g., in the standard input/terminal.Group of answer choicesTrueFalse

What is the value of the variable answer after the following code is executed?String str1 = "apple", str2 = "banana";boolean answer = str1.equals(str2) || (str1.length() > str2.length());

import java.io.*;import java.util.*;public class Solution { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int Myint = scanner.nextInt(); double d = scanner.nextDouble(); scanner.nextLine(); String mystring = scanner.nextLine(); System.out.println(mystring); System.out.println(d); System.out.println(Myint); /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ }}

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.