112k views
2 votes
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

User Walkytalky
by
5.5k points

1 Answer

3 votes

Answer:

import java.util.Scanner;

public class Main {

public static void main(String[] args) throws Exception {

Scanner myObj = new Scanner(System.in);

//Request and receive first String

System.out.println("Enter username");

String firstString = myObj.nextLine();

//Request and receive second string

System.out.println("Enter second string");

String secondString = myObj.nextLine();

//Request and receive third string

System.out.println("Enter third string");

String thirdString = myObj.nextLine();

//Concatenate the first and second string

String concatA_B = firstString + secondString;

if(concatA_B.equals(thirdString)){

System.out.println("First String Concatenated to Second String is equals to the third String");

}

else{

System.out.println("First String Concatenated to Second String is NOT equals to the third String");

}

}

}

Step-by-step explanation:

  • Import Scanner Class
  • Request and Receive three variables from the user using the Scanner Class
  • Concatenate the first and second
  • Use the .equals() method to check for equality
User Michael JDI
by
4.6k points