Java Assignment 1 Basic-New
Java Assignment 1 Basic-New
JAVA ASSIGNMENT -1
1. Create two integer variables (a and b) after that assign value for them. Then swap
value of a and b.
Hint: Using a c variable to transfer value temporary.
2. Write a program to input three numbers as math, physics, and chemistry. Output
average and rank according to the following:
AVG Rank
>=8.0 A
>=6.5 B
>=5.0 C
<5.0 D
Hint: Declare average and rank variable and calculate value for them.
3. Write a program to find x from ax + b =0 equation with a and b are input from
keyboards.
4. Write a program to find x from ax2 + bx + c =0 equation with a and b are input from
keyboards.
6. Write a program accepts an integer number (n) from user the calculate n!(factorial of
n) then display the result to the screen.
1
Professional Programmer Training Center
- Edit program to permit user inputs a list of student from keyboard until “n” key
pressed.
10. Write program to accepts two integer numbers (a and b), then calculate
and display their greatest common divisor.
Hint: define function int greatestCommonDivisor(int a, int b)
Example: greatestCommonDivisor (18, 12) = 6;
(Ước số chung lớn nhất – Có thể xem thuật toán trên mạng)
12. Write a program to accept an integer number and print the rectangle as
below: (use loop statement)
Example:
N=3
***
***
***
N=4
****
****
****
****
13. Write a program to accept an integer number and print the triangle as
below: (use loop statement)
Example:
N=3
*
**
***
N=4
*
**
14. Write a program to accept an integer number and print the triangle as
below: (use loop statement)
Example:
N=3
*
**
***
N=4
*
**
***
****
The End