Using String Data Type

Practise your skills and try to change the code. Read the comments and try what is within the TODO comment.

class StringDemo {
    public static void main (String[] args) {
        //The String data type is used to hold a sequence of characters
        //We use double quotes to enclose the value of the String
        String username = "joseph";
        String email = "[email protected]";
        System.out.println("username " + username);

        String firstName = "Joseph";
        String lastName = "Kandi";
        //We can use the + operator to join String values together
        String fullName = firstName +" "+ lastName;
        System.out.println("fullName " + fullName);

        //The String type is an object type
        //It comes with several functions or method to operate on its data
        //toUpperCase() is a method on the String class. 
        //We will discuss objects and method later, for now, toUpperCase() makes the value uppercase
        String fullNameCapitalized = fullName.toUpperCase();
        System.out.println(fullNameCapitalized);

        //TODO
        //Try figure out how to change the name to lower case
        //Create a variable with your own first name
        //Create a variable last name
        //Print your first name in lowercase to the console
        //Print your last name value in uppercase
        //Join your lowercase first name with your uppercase last name 
        //Print the result to the console
    }
}
  

results matching ""

    No results matching ""