Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Let\'s perform some magic tricks with strings! Write a program that will have th

ID: 3847248 • Letter: L

Question

Let's perform some magic tricks with strings!

Write a program that will have the user input two strings.

Output the result of the following ' tricks' in a visually appealing format.

Compare the two strings for equivalence.

Output the length of each string.

Output the 6th character in each string (nothing if there is no 6th character).

String Magician Rubric Print This Page Criteria Level S Level 4 Level 3 Level 2 String Manipulation Effectively handles Effectively ndles use Handle Handles use ut, with is er in Use ety of tring Effecti two strings methods to manipulate strings strings and returns results Effectively compares two Effectively outputs the length of Outputs the length of each Outputs the length of each strings and returna results Effectively Effectivel Outputs with 1 is ng Effectively o he sixth Performs another string manipulatio Internal Documentation Date, Dav Version Date, D Date, D Date, Dav Version Detailed description of program Description of program Limited d Prog Prog Every methods ds has a method Some method Every met Mo ripti Frequent line descriptions Alvi Pti Demonstrates understanding of Demonstrates understanding of topic topic Other exemplary features Works Independently Pseudo code is present Pseudo code somewhat ready Robust. 1 Crash Compiles and runs Unique features Level 1 cessfully ndles use strings and retums results Uns ully ixth ch Date, D Pti Fewono methods have Fewno line descriptions Multiple logic errors Level 0 No evidence

Explanation / Answer

Output

Enter The First String: Java Programming
Enter The Second String: RunTime Environment
Both Strings Are Different
Length Of First String Is: 16
Length Of Second String Is: 19
Sixth Character Of First String Is: P
Sixth Character Of Secondt String Is: m

Program:

import java.util.Scanner;

public class Strin {

   public static void main(String[] args) {
       Scanner s = new Scanner(System.in);
       System.out.print("Enter The First String: ");
       String firstString = s.nextLine();
       System.out.print("Enter The Second String: ");
       String secondString = s.nextLine();

       // Comparing The Strings
       if (firstString.equals(secondString))
           System.out.println("Both Strings Are Equal");
       else
           System.out.println("Both Strings Are Different");

       // Printing out length Of Each String
       int lenFirstString = firstString.length();
       int lenSecondString = secondString.length();
       System.out.println("Length Of First String Is: " + lenFirstString);
       System.out.println("Length Of Second String Is: " + lenSecondString);

       // Printing out 6th Character Of Each String

       // For First String
       if (lenFirstString < 6)
           System.out.println("Sixth Character Of First String Is: " + "");
       else
           System.out.println("Sixth Character Of First String Is: " + firstString.charAt(5));// Index
                                                                                               // starts
                                                                                               // from
                                                                                               // 0

       // For Second String
       if (lenSecondString < 6)
           System.out.println("Sixth Character Of Second String Is: " + "");
       else
           System.out.println("Sixth Character Of Secondt String Is: " + secondString.charAt(5));
   }
}