Create 3 java variables an intage a doublegpa and a Stringho
Create 3 java variables, an int(age), a double(gpa), and a String(homeTown).
Ask the user to input his or her home town and do the following with the home town:
Print a message welcoming the person from their home town.
Capitalize (upperCase()) all letters in the home town and print it again. hint: ( upperTown = homeTown.toUpperCase(); )
print out the number of letters in the home town. hint: (int len=homeTown.length();)
Solution
package myProject;
 import java.util.*;
 public class StringOperation
 {
    public static void main(String ss[])
    {
        //Scanner class object created
        Scanner sc = new Scanner(System.in);
        //Accepts age
        System.out.println(\"Enter the age: \");
        int age = sc.nextInt();
        //Accepts gpa
        System.out.println(\"Enter the gpa: \");
        double gpa = sc.nextDouble();
        //Clear console
        sc.nextLine();
        //Enter home town
        System.out.println(\"Enter the home town: \");
        String homeTown = sc.nextLine();
        //Welcome message
        System.out.println(\"Welcome to your home town: \" + homeTown);
        //Converts to upper case
        String upperTown = homeTown.toUpperCase();
        System.out.println(\"Your home town: \" + upperTown);
        //Counts the number of characters in home town
        System.out.println(\"Number of letters in your home town: \" + homeTown.length());
    }
 }
Output
Enter the age:
 12
 Enter the gpa:
 56.2
 Enter the home town:
 Berhampur
 Welcome to your home town: Berhampur
 Your home town: BERHAMPUR
 Number of letters in your home town: 9

