You are on page 1of 4

CS 1100 Homework 3 Due Date: 9/8/2021, 11:59 pm Total points: 30 points

You will submit a single zipped IntelliJ project containing your 6 solutions. Do not to use the
proper naming convention for your project, and to include a description of your program
at the top of you Java class, proper indenting, and appropriate comments.

1. Write a program to display the multiplication facts for a number. The user will enter a
value and then a table will be displayed showing the multiplication facts for that
value. Use a while-loop.

Please enter a number: 3

Multiplication table for 3


Multiplier Result
--------------------------------
1 3
2 6
3 9
4 12
5 15
6 18
7 21
8 24
9 27
10 30

Hint: The header (column names and the ----‘s) will be printed prior to entering the while
loop.
Steps.

2. Same as problem #1, but with a for-loop. Write a program to display the
multiplication facts for a number. The user will enter a value and then a table will be
displayed showing the multiplication facts for that value.

Please enter a number: 3

Multiplication table for 3


Multiplier Result
--------------------------------
1 3
Page 1 of 4
2 6
3 9
4 12
5 15
6 18
7 21
8 24
9 27
10 30

Hint: The header (column names and the ----‘s) will be printed prior to entering the
for loop.

3. Problem 5.3 from the textbook.


(Conversion from kilograms to pounds) Write a program that displays the following
table (note 1 kilogram is 2.2 pounds):

Kilograms Pounds
------------------------
1 2.2
3 6.6
5 11.0
7 15.4
9 19.8
11 24.2
13 28.6
15 33.0
17 37.4
19 41.8

Use a for-loop to solve this problem. Additionally, to format your output into the nice
columns, use printf and formatters. See 4.6 on how to format. Table 4.12 explanation
of %10.f is a good hint.

Hint: The header (column names and the ----‘s) will be printed prior to entering the
for loop.

4. Write a program that reads integers greater than zero, and displays the average
and sum of the numbers entered. The program will continue to prompt for

Page 2 of 4
numbers until the user enters a -1, to indicate termination of input. A sample run
is a follows:
Please enter a value (>0) or terminate with -1: 10
Please enter a value (>0) or terminate with -1: 3
Please enter a value (>0) or terminate with -1: 4
Please enter a value (>0) or terminate with -1: -1
The sum is 17
The average is 5.666666666666667

Hint: Recall that to obtain a double value from integer division, you will need to cast
the result to a double.
i.e. 5/3 is a result of 1, but, (double)5/3 is a result of 1.6666666666666667

Hint: You will need to use a sentinel controlled while loop in your solution.

5. Write a program that reads 10 integers and displays the largest value that was
entered. Use a for-loop, do…while loop, or while loop -- your choice.

Enter 10 values:

10 15 25 5 4 12 33 20 22 12

The largest value is: 33

6. Write a program that prompts the user to enter a list of values 1-5 and terminate
input with a 0 (zero). Your program should display the number of 1s 2’s, 3’s, 4’s,
and 5’s that were entered. You will need to use a sentinel controlled while loop.
Do not use arrays in your solutions, but rather a counter for 1’s, 2’s, etc.

Enter a value 1-5 or 0 to stop:


1
2
3
4
3
2
1
2
3
4

Page 3 of 4
5
0

Output
1's 2
2's 3
3's 3
4's 2
5's 1

Page 4 of 4

You might also like