In your textbook, this homework problem is in section 4.12 Homework 5-1.
Write a Java program that uses an int
variable num
which starts
at 1
.
Your program will have a loop that will continue as long as num
is less than
or equal to 30
. The loop will do the following
num
is odd, you should output: num is an odd number
num
is even, you should output: num is an even number
num
is divisible by 3, you should output: num is divisible by 3
num
is divisible by 5, you should output: num is divisible by 5
num
is divisible by 7, you should output: num is divisible by 7
num
is divisible by 9, you should output: num is divisible by 9
num
Please note that your class should be named FirstLoop.
In your textbook, this homework problem is in section 4.13 Homework 5-2.
Write a program to read a list of exam grades given as int
's in the range of
0
to 100
. Your program will display the total number of grades
and the number of grades in each letter-grade category as follows:
Use a negative number as a sentinel value to indicate the end of the input. (The negative value is used only to end the loop, do not use it in your calculations.)
Each time you prompt the user to enter a grade you will print:
Enter a grade:
For example, if the input is:
98 95 87 86 83 92 85 78 74 72 81 71 69 63 50 43 -1
The output would be:
Total number of grades = 16 Number of A's = 2 Number of A-'s = 1 Number of B+'s = 1 Number of B's = 3 Number of B-'s = 1 Number of C+'s = 1 Number of C's = 1 Number of C-'s = 2 Number of D's = 2 Number of F's = 2
Please note that your class should be named Grades.