Assignment 2
Q1) Write a program that for computing an average of five marks and printing its
degree. Your program should read five marks for a student in addition to the student
name. Afterwards, the program computes the average using for loop and prints the
degree according the conditions below:
• If average ≥ 86, degree is Excellent
• If 86 > average ≥ 76 , degree is Very Good
• If 76 > average ≥ 68, degree is Good
• If 68 > average ≥ 60, degree is Moderate
• Otherwise, degree is Fail
Sample Output:
Enter your name: Ahmad
Enter mark 1: 60
Enter mark 2: 70
Enter mark 3: 80
Enter mark 4: 90
Enter mark 5: 100
-----------------------------------------------
Name: Ahmad
Average: 80
Degree: Very Good
Enter your name: Fatema
Enter mark 1: 60
Enter mark 2: 55
Enter mark 3: 70
Enter mark 4: 50
Enter mark 5: 75
-----------------------------------------------
Name: Fatema
Average: 62
Degree: Moderate
Page 1 of 2
Q2) To compute 25 we write [Link](2,5). The power means to multiply the base
number itself (2 in our example) by an exponent number times (5 in our example),
which is in the following form:
[Link](2,5) = 2 * 2 * 2 * 2 * 2 = 32
Now, you should write a java program that reads two integer numbers from the user,
then finds and prints the power of first number to the second by using for loops (don’t
use [Link]( ) method ) .
- Also, in the same program, you should find the factorial of the second number, the
factorial is computed as following (for example 5!):
5! = 5 * 4 * 3 * 2 * 1
Enter First Number: 2
Enter Second Number: 5
-----------------------------------------------
2^5 = 32
5! = 120
Enter First Number: 3
Enter Second Number: 4
-----------------------------------------------
3^4 = 81
4! = 24
Page 2 of 2