> Example problems: > 1. Write a loop to draw N circles in a horizontal row, each of diameter 50, > and starting at x=0, y=100. The y coordinate never changes; > the x coordinate is incremented by 50 each time. x=0; y=100; for (i=0; i 2. Write a loop to add up the numbers from 1 to N. > Put it inside a function that takes N as a parameter. public int sumnums(int N) { int i; int sum = 0; for (i=1; i<=N; i++) { sum += i; } return sum; } > 3. Write a function printMultiple that takes two parameters, > an int n and a char ch, and prints n copies of that character: > printMultiple('a', 4) should yield aaaa. public void printMultiple(int n, char ch) { int i; for (i=0; i 4. *Using* the function printMultiple above, write a loop to draw > * > *** > ***** > ******* > (each row has two more *'s than the previous row.) int starcount = 1; for (row=1; row<= maxrow; row++) { // suppose maxrow is given printMultiple(starcount, '*'); starcount += 2; // increase by 2 each time } > 5. Write a function that reverses a string: > public String reverse (String s) { > } > This one is hard, although we did do a class example about this. > Hint: let n = s.length(). The letters of s are s.charAt(n-1) down to > s.charAt(0). Append these (with +=) in turn to an initially empty string. public String reverse (String s) { int n; String rev = ""; for (n=s.length()-1; n>=0; n--) { // note s.length() - 1 rev += s.charAt(n); } return rev; }