Java Reference
In-Depth Information
EX 6.4 Transform the while loop from the previous exercise into an
equivalent for loop (make sure it produces the same output).
EX 6.5 Write a do loop that verifies that the user enters an even integer
value.
EX 6.6 Write a for loop to print the odd numbers from 1 to 99
(inclusive).
EX 6.7 Write a for loop to print the multiples of 3 from 300 down to 3.
EX 6.8 Write a code fragment that reads 10 integer values from the user
and prints the highest value entered.
EX 6.9 Write a code fragment that determines and prints the number of
times the character 'a' appears in a String object called name .
EX 6.10 Write a code fragment that prints the characters stored in a
String object called str backward.
EX 6.11 Write a code fragment that prints every other character in a
String object called word starting with the first character.
EX 6.12 Write a method called powersOfTwo that prints the first 10 pow-
ers of 2 (starting with 2). The method takes no parameters and
doesn't return anything.
EX 6.13 Write a method called alarm that prints the string "Alarm!" mul-
tiple times on separate lines. The method should accept an inte-
ger parameter that specifies how many times the string is printed.
Print an error message if the parameter is less than 1.
EX 6.14 Write a method called sum100 that returns the sum of the inte-
gers from 1 to 100, inclusive.
EX 6.15 Write a method called sumRange that accepts two integer param-
eters that represent a range. Issue an error message and return
zero if the second parameter is less than the first. Otherwise,
the method should return the sum of the integers in that range
(inclusive).
EX 6.16 Write a method called countA that accepts a String parameter
and returns the number of times the character 'A' is found in the
string.
EX 6.17 Write a method called reverse that accepts a String parameter
and returns a string that contains the characters of the parameter
in reverse order. Note that there is a method in the String class
that performs this operation, but for the sake of this exercise,
you are expected to write your own.
Search WWH ::




Custom Search