140.
a.
b.
c.
The String class has a method called toUpperCase(). This can
be used to convert a String to uppercase.
The following code
demonstrates this:
String myStr = “Hello World”;
myStr = myStr.toUpperCase();
System.out.println(myStr);
This code creates a String called myStr with the value Hello
World. It invokes the toUpperCase() method
on this String
object. So, this code prints the following output:
HELLO WORLD
Explain how you can convert an Integer to a String.
Answer:
There are several ways in which you can convert an Integer to a
String. These are as follows:
Directly enclosing the Integer in quotes:
You can enclose the
number in quotes and assign to a String variable as follows:
String strNum = “10”;
Using String.valueOf: The String class has a valueOf
method. You can use this to convert
an Integer to a String as
shown below:
String strNum = String.valueOf(10);
Using the Integer.toString method: The Integer class
has a toString method. This
can also be used to convert
an Integer to a String as shown below: