CSci 1211 Problem set 5. Due Friday, Feb. 20th at 5pm

Problem 1 (8 points)

Write a program to read an integer from the user's input and print out the following two triangles (assuming the user entered 5):

*****
 ****
  ***
   **
    *
    *
   **
  ***
 ****
*****
You may use the solution to the first two lab questions (the upper left and the lower left triangles).

Problem 2 (5 points)

Write a program that will read a string and print it out so that letters at even-numbered positions (0, 2, etc.) are capitalized and letters at odd-numbered positions are lower case. Non-letter characters are not changed.

Hint: to convert a Java character into upper case, you need to use the method Character.toUpperCase(). Here is an example:


char c = 'a';
c = Character.toUpperCase(c); // create 'A', store it in c
(use Character.toLowerCase(c) to convert to lower-case). Alternatively you can create two additional strings: an upper-case version of the input string and the lower-case one and copy or print characters from those strings.

Here is a sample run of a program using some weird Russian name as an input :-)


Please enter a string: elena MACHKASOVA
The result is: ElEnA MaChKaSoVa
4 points of extra credit will be given if your program doesn't use an if/else statement inside the loop. The program must work correctly on all strings.

Problem 3 (5 points)

Write a program that reads integer numbers as input from the user and counts the number of odd and even numbers. The program stops when the user enters -1. At the end the program displays the two counts. It also prints out a message saying whether there has been more odd or even numbers.

Problem 4 (8 points)

Problem 18 p. 159. Clarification: compute the "intrinsic" sine function using Math.sin (see p. 43).

Problem 5 (7 points)

Write a program that reads strings from the user while the strings are in alphabetical order (from a to z). The first string that comes out of order stops the program. Here is an example of how the program works:

Please enter a string: apple
Please enter a string: banana
Please enter a string: grape
Please enter a string: orange
Please enter a string: kiwi
kiwi comes before orange. Good bye!
You may assume that all the strings are lower-case.
This page is a part of the course CSci 1211 at UMM.

The views and opinions expressed in this page are strictly those of the page author. The contents of this page have not been reviewed or approved by the University of Minnesota.