Using String
Data Type
Practise your skills and try to change the code. Read the comments and try what is within the TODO comment.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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 = "john.doe@example.com";
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
}
}