Java Reference
In-Depth Information
Self-Test Exercises
24. What is the output produced by the following?
String verbPhrase = "is money";
System.out.println("Time" + verbPhrase);
25. What is the output produced by the following?
String test = "abcdefg";
System.out.println(test.length());
System.out.println(test.charAt(1));
26. What is the output produced by the following?
String test = "abcdefg";
System.out.println(test.substring(3));
27. What is the output produced by the following?
System.out.println("abc\ndef");
28. What is the output produced by the following?
System.out.println("abc\\ndef");
29. What is the output produced by the following?
String test = "Hello Tony";
test = test.toUpperCase();
System.out.println(test);
30. What is the output of the following two lines of Java code?
System.out.println("2 + 2 = " + (2 + 2));
System.out.println("2 + 2 = " + 2 + 2);
31. Suppose sam is an object of a class named Person and suppose increaseAge
is a method for the class Person that takes one argument that is an integer.
How do you write an invocation of the method increaseAge using sam as
the calling object and using the argument 10 ? The method increaseAge will
change the data in sam so that it simulates sam aging by 10 years.
32. The following code is supposed to output the string in lowercase letters but it
has an error. What is wrong?
String test = "WHY ARE YOU SHOUTING?";
test.toLowerCase();
System.out.println(test);
 
Search WWH ::




Custom Search