ptg7068951
Q&A 75
Q&A
Q. How can I set the value of a string variable to be blank?
A. Use an empty string,a pair of double quotation marks without any text
between them. The following code creates a new string variable called
adaSaysand sets it to nothing:
String adaSays = “”;
Q. I can’t seem to get the toUpperCase()method to change a string so
that it’s all capital letters. What am I doing wrong?
A. When you call a String object’s toUpperCase()method,it doesn’t actually
change the String object it is called on. Instead,it creates a new string
that is set in all uppercase letters. Consider the following statements:
String firstName = “Nessie”;
String changeName = firstName.toUpperCase();
System.out.println(“First Name: “+ firstName);
These statements display the text First Name: Nessie because
firstName contains the original string. If you switched the last state-
ment to display the changeName variable instead,it would output First
Name: NESSIE.
Strings do not change in value in Java after they are created.
Q. Do all methods in Java display trueorfalsein the same way that
theequals()method does in relation to strings?
A. Methods have different ways of producing a response after they are
used. When a method sends back a value,as the equals()method
does,it’s called returning a value. The equals()method is set to return
a Boolean value. Other methods might return a string,an integer,anoth-
er type of variable,or nothing at all—which is represented by void.
Q. Why do schools assign grades the letters A,B, C, D and F but not E?
A. The letter grade E already was being used in an alternative grading sys-
tem. Until the mid-20th century,in the United States the most popular
grading system was to assign E for excellent,S for satisfactory,N for
needs improvement or U for the dreaded unsatisfactory. So when the
ABCD system came along,giving a failing student an E was considered
a not-so-excellent idea.
ESNU grading remains in wide use in elementary schools.