Write a method that takes two parameters, a char and an
int.
It prints the first parameter the number of times given by the
second parameter.
Use the method from part a) to write a code segment to output a
triangular pattern of asterisks like the one below.
The first row has only one asterisk and the last row has no leading blanks.
All rows other than the first and last contain exactly two asterisks.
The variable rows contains the number of rows. This is the same as
the number of lines of output. You may assume that
rows is at least 2.
For rows = 6 the pattern looks like:
*
* *
* *
* *
* *
***********
(5 points)
Write a code segment that sets the integer variable count to the number
of times the letter 'A' occurs in the String s.
(10 points)
Write a code segment that declares and allocates a 2-dimensional
array of doubles with 100 rows and 20 columns.
Write a method that takes an arbitrary rectangular 2-dimensional array of
doubles and a column number as parameters and returns the average of the
elements in the given column. If the column is empty, return 0.
(18 points)
Write a class called TextBook
to hold information about a book for a course. A textbook has
a title, an author, a course number and a price. Have the class implement
Comparable with the comparison by title. Show the entire code for
the class including a constructor, accessor and modifier methods for all
attributes, and all methods needed to implement Comparable.
(7 points) Given the following declarations, find the value indicated.
String s = new String("ABCDEFGABCDEFG");
String t = new String("DEF");
String u = new String("DEF");
String v = new String("ABD");
s.length();
s.substring(5)
s.substring(3,8)
s.indexOf(t)
s.indexOf(v)
t == v;
t.equals(v);
(10 points)
Write a method, findLargest, that takes a single array of
integers as a parameter and returns the index of the largest value in the array.
If the array contains no elements, return -1. If there are several entries
that have the largest value, return the index of the first such entry.
Write a method, findLargestFromEnd, which is similar to the
one above, but if there are several entries that have the largest value,
return the index of the last such entry.
Write a method, findLargest5, that takes a single
array of integers as a parameter and returns the value of the largest
entry in the array that is divisible by 5. If there are no such values,
return -1. Be sure that your method works even if the array only contains
negative values.