Ask Question
7 January, 04:24

Write a program that asks the user for three strings. Then, print out whether the first string concatenated to the second string is equal to the third string. Here are a few sample program runs:

Sample Program 1:

First string? pepper

Second string? mint

Third string? peppermint

pepper + mint is equal to peppermint!

Sample Program 2:

First string? go

Second string? fish

Third string? donuts

go + fish is not equal to donuts!

public class ThreeStrings extends ConsoleProgram

{

public void run ()

{

code

}

+1
Answers (1)
  1. 7 January, 07:59
    0
    import java. util. Scanner;

    public class num5 {

    public static void main (String[] args) {

    Scanner in = new Scanner (System. in);

    System. out. println ("Enter The First String");

    String str1 = in. next ();

    System. out. println ("Enter The Second String");

    String str2 = in. next ();

    System. out. println ("Enter The Third String");

    String str3 = in. next ();

    String oneAndTwo = str1+str2;

    if (str3. equals (oneAndTwo)) {

    System. out. println (str1+" + "+str2+" is equal to "+str3+"!");

    }

    else

    System. out. println (str1+" + "+str2+" is not equal to "+str3+"!");

    }

    }

    Explanation:

    Implemented in Using Java Programming Language Import Scanner Class to prompt and receive users' input Create three string variables and store the three values entered by the user (str1, str2 and str3) Concatenate str1 and str2 using the + operator and assign to a new variable Use the if statement with Java's. equals () method to check for equality of the new string with the third string Print the appropriate message if the equal or not
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a program that asks the user for three strings. Then, print out whether the first string concatenated to the second string is equal ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers