In: Computer Science
In a file called LengthSum.java, write a program that:
- Asks the user to enter a string.
- Asks the user to enter a second string.
- Prints out the length of the first string, the length of the second string, and the sum of the two lengths, using EXACTLY the same format as shown below.
For example: if the user enters strings "UT" and "Arlington", your program output should look EXACTLY like this: Please enter a string: UT Please enter a second string: Arlington The first string has length 2. The second string has length 9. The sum of the two lengths is 11. Your program's output should match EXACTLY the format shown above. There should be no deviations, no extra spaces or lines, no extra punctuation in your output. What you see above as uppercase letters should remain uppercase in your output, what you see as lowercase letters should remain as lowercase in your output, what you see as spaces and punctuation should remain exactly as spaces and punctuation in your output.
import java.util.Scanner;
public class LengthSum {
public static void main(String[] args) {
// TODO Auto-generated method
stub
Scanner sc=new
Scanner(System.in);
System.out.print("Please enter a
string:");
String
first_one=sc.nextLine();
System.out.print("Please enter a
second string:");
String
second_one=sc.nextLine();
System.out.println("The first
string has length "+first_one.length()+".");
System.out.println("The second
string has length "+second_one.length()+".");
System.out.println("The sum of the
two lengths is "+
(first_one.length()+second_one.length())+".");
}
}
Expected output: