JAVA Task 4 Fun with Strings Write a program that works wit
JAVA
Task #4 – Fun with Strings
Write a program that works with String methods.
As input, prompt the user to enter their first and last name.
Concatenate your first and last name
For your output, display the following:
1.Your first name in all upper case
2.Your full name in all lower case
3.The 7th character (from the left) of your full name
4.The number of characters in your full name
5. Your Initials – (the first letter of your first name and the first letter of your last name – with no space between them)
Note: Be sure to provide user friendly input and output!!!
I expect you to provide me with the source code for this task.
Solution
StringsFun.java
import java.util.Scanner;
public class StringsFun {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print(\"Enter first name: \");
String firstName = scan.next();
System.out.print(\"Enter last name: \");
String lastName = scan.next();
String fullName = firstName +\" \"+lastName;
System.out.println(\"First name in all upper case: \"+firstName.toUpperCase());
System.out.println(\"Full name in all lower case: \"+fullName.toLowerCase());
System.out.println(\"The 7th character (from the left) of your full name: \"+fullName.charAt(6));
System.out.println(\"The number of characters in your full name: \"+fullName.length());
System.out.println(\"Initials: \"+firstName.charAt(0)+lastName.charAt(0));
}
}
Output:
Enter first name: Suresh
Enter last name: Murapaka
First name in all upper case: SURESH
Full name in all lower case: suresh murapaka
The 7th character (from the left) of your full name:
The number of characters in your full name: 15
Initials: SM
