R-1.1 Write a short Java method, inputAllBaseTypes
, that inputs a different value of each base type from the standard
input device and prints it back to the standard output device.
R-1.2 Suppose that we create an array A
of GameEntry
objects, which has an integer scores
field, and we clone A
and
store the result in an array B
. If we then immediately set A[4].scores
equal to 550, what is the score value of the
GameEntry
object referenced by B[4]
?
R-1.3 Write a short Java method, isMultiple
, that takes two long
values, n and m, and returns true if and only if n is a multiple of m, that is,
R-1.4 Write a short Java method, isEven
, that takes an int i and returns true if and only if i is even. Your method cannot use the multiplication, modulus, or division operators, however.
R-1.5 Write a short Java method that takes an integer n and returns the sum of all positive integers less than or equal to n.
R-1.6 Write a short Java method that takes an integer n and returns the sum of all the odd positive integers less than or equal to n.
R-1.7 Write a short Java method that takes an integer n and returns the sum of the squares of all positive integers less than or equal to n.
R-1.8 Write a short Java method that counts the number of vowel in a given character string.
R-1.9 Write a short Java method that uses a StringBuilder
instance to remove all the punctuation from a string s storing a sentence, for example, transforming the string "Let's try, Mike!" to "Lets try Mike".
R-1.10 Write a Java class, Flower, that has three instance variables of type String, int, and float, which respectively represent the name of the flower, its number of petals, and price. Your class must include a constructor method that initializes each variable to an appropriate value, and your class should include methods for setting the value of each type, and getting the value of each type.