Tải bản đầy đủ (.docx) (2 trang)

Bài tập vòng lặp java

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (16.27 KB, 2 trang )

Bài Tập Vòng Lặp JAVA
1.

Write a program that has one parameter that specifies an integer n and prints n copies of 1,
followed on the next line by n-1 copies of 2, followed on the next line by n-2 copies of 3, …
with the last line printing one n. You may assume n is positive. As an example, printN(6)
would result in the following output:

111111
22222
3333
444
55
6
2.

3.

2. Write an algorithm to accept a number between 1 and 9 and display a pattern. For
example, if the number entered is 5, the following pattern should be displayed:
1
21
321
4321
54321
Write a program to read an integer number (n>0). Write flowing methods:
- Checking whether the input number is a prime number or n
- Print out prime submultiples of number n
- Generate the first 100 prime numbers.

4. Write a program to read an integer number (n>0). Write following methods:


- Checking whether a number is a perfect number or not?
- Generate the first n perfect numbers.
5. Write a program that computes:
P = 1!+ 2!+ 3!+…+ n!


S1= 12 + 22 +…+ n2
6. Write a method to read a number (N>0) from keyboard and compute sum of number’s numerals.
Example: Suppose N = 25364, N include 5 numerals: 2, 5, 3, 6, 4. The sum of number’s numerals.
7. Write a program to find Highest Common Factor (HCF) and Least Common Multiple of two integer
numbers.



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×