View the step-by-step solution to:


1. What is a well-documented (commented) program, "RelativelyPrimeArray," that takes an integer command-line

argument "n" and creates an (n+1)-by-(n+1) Boolean array "rpa" such that rpa[i][j] (for i,j>0) is true if i and j are relatively prime (have no common factors), and is false otherwise. It should then output as is shown by the sample run below. If the indexes i,j (for i,j>0) are equal, it should output a single space. If the indexes are not equal, then it should output a "T" character if the array element specified by the indexes is true or an "F" character if it is false. [MO2.1, MO2.2]

A sample run would be as follows. 

> java RelativelyPrimeArray 9 

  1 2 3 4 5 6 7 8 9 

1  T T T T T T T T 

2 T  T F T F T F T 

3 T T  T T F T T F 

4 T F T  T F T F T 

5 T T T T  T T T T 

6 T F F F T  T F F 

7 T T T T T T  T T 

8 T F T F T F T  T 

9 T T F T T F T T

2. What is a well-documented (commented) program, "Distribution100," that takes integer command-line arguments. The first argument would be the count of the remaining arguments that are between 1 and 100 (inclusive of 1 and 100). It then prints out the count of numbers entered that are less than or equal to 50 and the count of numbers that are greater than 50 from those remaining arguments. [MO2.1, MO2.2]

A sample run would be as follows.

> java Distribution100 15 5 82 2 1 74 19 47 64 39 77 25 99 100 1 10 

9 numbers entered are less than or equal to 50. 

6 numbers entered are greater than 50.

3. What is a well-documented (commented) program, "Average," that reads in lines from standard input with each line containing a name and three integers and then uses "printf()" to print a table with a column of the names, the integers, and the average of the three integers accurate to two decimal places. The user will specify the number of names as a command-line argument and then type in that number of names (along with three integers for each name). [MO2.1, MO2.2]

A sample run would be as follows. 

> java Average 4 

Joe 3 5 2 

Tim 4 1 5 

Jane 6 3 2 

Jack 8 3 5


Joe 3 5 2 3.33 

Tim 4 1 5 3.33 

Jane 6 3 2 3.67 

Jack 8 3 5 5.33

Top Answer

Sample output: Sample output for part 1. "RelativelyPrimeArray parogram". C:UsersMayankDesktop New folder&gt;javac... View the full answer


Sign up to view the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question