0% found this document useful (0 votes)
3 views28 pages

CONLIB_Ch_20241014161918

Uploaded by

abinav2010p
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views28 pages

CONLIB_Ch_20241014161918

Uploaded by

abinav2010p
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

G RADE 9

ICT

C H .8 - I TERATIVE C ONSTRUCTS IN J AVA


( L OOPS )
P ROGRAMS
1. Write the program in Java to display the first ten terms of the below series:
1, 4, 9, 16 . . . . . . . . . . . . . . . .
V A RI A B L E D E S C RI PT I O N :

P R O GR AM C O D I N G :

2. Write the program in Java to display the first ten terms of the below series:
3, 6, 9, 12 . . . . . . . . . . . . . . . .
V A RI A B L E D E S C RI PT I O N :

P R O GR AM C O D I N G :
3. Write the program in Java to display the first ten terms of the below series:
4, 8, 16, 32 . . . . . . . . . . . . . . . .
V A RI A B L E D E S C RI PT I O N :

P R O GR AM C O D I N G :
4. Write the program in Java to display the first ten terms of the below series:
1.5, 3.0, 4.5, 6.0, . . . . . . . . . . . . . . . .
V A RI A B L E D E S C RI PT I O N :

P R O GR AM C O D I N G :

5. Write the program in Java to display the first ten terms of the below series:
1, 9, 25, 49, . . . . . . . . . . . . . . . .
V A RI A B L E D E S C RI PT I O N :

P R O GR AM C O D I N G :
6. Write the program in Java to display the first ten terms of the below series:
4, 16, 36, 64, . . . . . . . . . . . . . . . .
V A RI A B L E D E S C RI PT I O N :

P R O GR AM C O D I N G :
7. Write a program in Java to find the sum of the below series:
1 + 4 + 9 + .... + 400
V A RI A B L E D E S C RI PT I O N :

P R O GR AM C O D I N G :

8. Write a program in Java to find the sum of the below series:

V A RI A B L E D E S C RI PT I O N :

P R O GR AM C O D I N G :
9. Write a program in Java to find the sum of the below series:
(1*2) + (2*3) + …… + (19*20)
V A RI A B L E D E S C RI PT I O N :

P R O GR AM C O D I N G :
10. Write a program in Java to find the sum of the below series:
1 + (1*2) + (1*2*3) + ... + (1*2*3*...*n)
V A RI A B L E D E S C RI PT I O N :

P R O GR AM C O D I N G :

11. Write a program to input any 50 numbers (including positive and negative). Perform the following tasks:
(a) Count the positive numbers
(b) Count the negative numbers
(c) Sum of positive numbers
(d) Sum of negative numbers
V A RI A B L E D E S C RI PT I O N :

P R O GR AM C O D I N G :
12. Write a program to calculate the sum of all odd numbers and even numbers between a range of numbers from
m to n (both inclusive) where m < n. Input m and n (where m < n).
V A RI A B L E D E S C RI PT I O N :

P R O GR AM C O D I N G :
13. Write a program to display the product of positive even numbers and sum negative odd numbers from a list
of numbers entered by the user. The list terminates when the user enters zero from the console.
V A RI A B L E D E S C RI PT I O N :

P R O GR AM C O D I N G :

14. Write a program to enter any 20 numbers and check whether they are divisible by 5 or not. If divisible then
perform the following tasks:
(a) Display all the numbers ending with the digit 5.
(b) Count those numbers ending with 0 (zero).
V A RI A B L E D E S C RI PT I O N :

P R O GR AM C O D I N G :

15. Write a program to display all the numbers between m and n input from the keyboard (where m<n, m>0,
n>0), check and print the numbers that are perfect square. e.g. 25, 36, 49, are said to be perfect square
numbers.
V A RI A B L E D E S C RI PT I O N :
P R O GR AM C O D I N G :

16. Write a program to display all the 'Buzz Numbers' between p and q (where p<q). A 'Buzz Number' is the
number which ends with 7 or is divisible by 7.
V A RI A B L E D E S C RI PT I O N :
P R O GR AM C O D I N G :

17. Write a program to input a number and perform the following actions:
(a) Display all the digits in the number.
(b) Display the sum of digits in the number.
(c) Display the product of digits in the number.
V A RI A B L E D E S C RI PT I O N :
P R O GR AM C O D I N G :

18. Write a program to input a number and count the number of digits. The program further checks whether the
number contains odd number of digits or even number of digits.
Sample Input: 749
Sample Output: Number of digits = 3
The number contains odd number of digits.
V A RI A B L E D E S C RI PT I O N :

P R O GR AM C O D I N G :
19. Write a program to input a number and check if it is a palindrome number or not (A number is a Palindrome
which when read in reverse order is same as in the original number).
Sample Input: 747
Sample Output: Reversed Number = 747 (Palindrome number)
Sample Input: 4567
Sample Output: Reversed Number = 7654 (Not a palindrome number)
V A RI A B L E D E S C RI PT I O N :

P R O GR AM C O D I N G :
20. Write a program to input a number and check if it is an Armstrong number. (An Armstrong number is when
the sum of digit, raised to the power of number of digits)
Sample Input: 153
Sample Output: Number of digits = 3
13 + 53 + 33 = 1 + 125+ 27 = 153 (Armstrong Number)
Sample Input: 64
Sample Output: Number of digits = 2
62 + 42 = 36 + 16 = 52 (Not a Armstrong Number)

V A RI A B L E D E S C RI PT I O N :
P R O GR AM C O D I N G :

21. Write a program to input two numbers and find their GCD (Greatest Common Divisor.
Sample Input: 45, 20
Sample Output: GCD = 5
V A RI A B L E D E S C RI PT I O N :
P R O GR AM C O D I N G :

22. Write a menu driven program to accept a number from the user and check whether it is a Prime number or an
Automorphic number.
(a) Prime number: (A number is said to be prime, if it is only divisible by 1 and itself) Example: 3,5,7,11
(b) Automorphic number: (Automorphic number is the number which is contained in the last digit(s) of its
square.)
Example: 25 is an Automorphic number as its square is 625 and 25 is present as the last two digits.
V A RI A B L E D E S C RI PT I O N :
P R O GR AM C O D I N G :
23. Generate and display the n terms of the Fibonacci series (0, 1, 1, 2, 3, 5, ... , n-terms). The first two Fibonacci
numbers are 0 and 1, and each subsequent number is the sum of the previous two.
V A RI A B L E D E S C RI PT I O N :

P R O GR AM C O D I N G :
24. A special two-digit number is such that when the sum of its digits is added to the product of its digits, the
result is equal to the original two-digit number.
Example: Consider the number 59.
Sum of digits = 5 + 9 = 14
Product of digits = 5 * 9 = 45
Sum of the sum of digits and product of digits = 14 + 45 = 59
Write a program to accept a two-digit number. Add the sum of its digits to the product of its digits. If the value
is equal to the number input, then display the message "Special two-digit number" otherwise, display the
message "Not a special two-digit number".
V A RI A B L E D E S C RI PT I O N :

P R O GR AM C O D I N G :
25. Write a program to accept a number. Find and display all its factors (including 1 and excluding the number
itself).
Sample Input: 36.
Sample Output: 1 2 3 4 6 9 12 18
V A RI A B L E D E S C RI PT I O N :

P R O GR AM C O D I N G :
26. Write a program to find the factorial of the given number. (Factorial of 5! = 5*4*3*2*1 = 120)
V A RI A B L E D E S C RI PT I O N :

P R O GR AM C O D I N G :
27. Write a program to input a number. Check and display whether it is a Niven number or not. (A number is said
to be Niven which is divisible by the sum of its digits).
Example: Sample Input 126
Sum of its digits = 1 + 2 + 6 = 9 and 126 is divisible by 9.
V A RI A B L E D E S C RI PT I O N :

P R O GR AM C O D I N G :
28. Write a program to accept a number and check whether it is a 'Spy Number' or not. (A number is spy if the
sum of its digits equals the product of its digits.)
Example: Sample Input: 1124
Sum of the digits = 1 + 1 + 2 + 4 = 8
Product of the digits = 1*1*2*4 = 8
V A RI A B L E D E S C RI PT I O N :

P R O GR AM C O D I N G :
29. Write a program to accept a (decimal) number and convert it to its binary form (base 2).
Sample Input: 379
Binary: 101111011
V A RI A B L E D E S C RI PT I O N :

P R O GR AM C O D I N G :

30. Write a program to accept a binary number (base 2) and convert it to its decimal form (base 10).
Sample Input: 101111011
Decimal: 379
V A RI A B L E D E S C RI PT I O N :
P R O GR AM C O D I N G :

You might also like