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

9th programs-conditional and iterative

The document outlines various Java programming exercises focused on conditional constructs, series summation, and iterative constructs. It includes tasks such as calculating the sum of digits, checking for prime numbers, generating Fibonacci series, and identifying special numbers like Armstrong and perfect numbers. Additionally, it presents series summation formulas and iterative patterns for displaying sequences.

Uploaded by

dioxotwitch
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
3 views6 pages

9th programs-conditional and iterative

The document outlines various Java programming exercises focused on conditional constructs, series summation, and iterative constructs. It includes tasks such as calculating the sum of digits, checking for prime numbers, generating Fibonacci series, and identifying special numbers like Armstrong and perfect numbers. Additionally, it presents series summation formulas and iterative patterns for displaying sequences.

Uploaded by

dioxotwitch
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 6

I)Programs :Conditional constructs in java

1.Sum of the digit


Eg:=Input :123
Output :1+2+3=6

2.Reverse of a number
Eg:=Input :123
Output :321

3.Niven/Harshad number or not(Number which is divisible by the sum of its digits.eg:


126,1+2+6=9 and 126 is divisible by 9)

4.Spy number or not(sum of the digit is equal to product of the digit eg:=1124=1+1+2+4=8
and 1*1*2*4=8)
5.perfect number or not(Number which is equal to the sum of its factors other the number
itself.
Eg : 6=1+2+3

6.Palindrome or not(Number that remains same when its digit s are reversed.)

7. prime number or not(number has factors 1 and number itself)

8. composite number or not(number has one or more than one factors excluding 1 and
number itself)

9.pronic number/oblong number/rectangular number/heteromecic number or not(number


which is the product of two consecutive integer eg: 12=3 x 4 ,20=4x5)

10.Factorial of a number (eg :5!=5x4x3x2x1=120)

11. Factors of a given number(eg : Input :12 ,Factors are : 1,12,2,3,6,4)

12.Fibonacci series(0 1 1 2 3 5 8 13………)

13. Buzz number or not(number which ends with 7 or is divisible by 7.)

14.Write a program to input a number .Find the difference between highest and smallest
number. .(eg : input : 5134 ,output : 5-1=4)

15.Automorphic number(Number which is contained in the last digits of a square .


eg: 52=25 , 252=625)

16. A Dudeney number is a positive integer that is a perfect cube such that the sum of its
digits is equal to the cube root of the number. Write a program to input a number and check
and print whether it is a Dudeney number or not.
Example:
Consider the number 512.
Sum of digits = 5 + 1 + 2 = 8
Cube root of 512 = 8
As Sum of digits = Cube root of Number hence 512 is a Dudeney number.

17. Input a number and check if is an abundant number or not


Abundant number is a number in which the sum of its proper divisors is greater than the
number itself.
eg: 12 is an abundant number (1+2+3+4+6=16)
4 is an abundant number (1+2=3)

18. Write a program to enter 10 numbers and check whether they are divisible by 5 or not
.If divisible the perform the following tasks.
a. Display all the numbers ending with the digit 5
b .Count the numbers ending with 0

19. A tech number has even number of digits. If the number is split in two equal halves, then
the square of sum of these halves is equal to the number itself. Write a program to generate
and print all four digits tech numbers.
Example:
Consider the number 3025
Square of sum of the halves of 3025 = (30 + 25)2
= (55)2
= 3025 is a tech number.

20.Write a program to input any 50 numbers (including negative and positive )and perform
the following task.
a. Count the positive numbers
b. Count the negative numbers
c. sum of positive numbers
d. sum of negative numbers

21.Amstrong number or not(A number is called Armstrong number if the following equation
holds true for that number: xy..z = xn+yn+……..+zn where n denotes the number of digits in
the number)

22.A disarium number is a number where the sum of the digits raised to the power of their
respective position is equal to the number itself. For example, 135 is a disarium number because 135
= 11 + 32 + 53

23. A number is said to be Peterson if the sum of factorials of each digit is equal to the sum
of the number itself.
Suppose, we have to check the number (n) 145 is Peterson or not.
Number = 145
145 = !1 + !4 + !5
=1+4*3*2*1+5*4*3*2*1
=1+24+120
145=145
24.A number is called a tech number if the given number has an even number of digits and
the number can be divided exactly into two parts from the middle. After equally dividing the
number, sum up the numbers and find the square of the sum. If we get the number itself as
square, the given number is a tech number, else, not a tech number.
For example, 3025 is a tech number.

25.A positive integer whose sum of digits of its square is equal to the number itself is called
a neon number.

Eg: n=9 ,92=81, 8+1=9


II)Sum of series programs

1. S=x1 +x2 + x3+……..+ xn

1 2 3 n
2. 𝑠 = + + + ⋯+
𝑥 𝑥2 𝑥3 𝑥𝑛

3. S=x1 - x2 + x3- x4 …….. - xn where x=3

1 2 3 49
4. 𝑠 = + + + ⋯
2 3 4 50

𝑎 𝑎 𝑎 𝑎
5. 𝑠 = 𝑎 + + + +⋯
2 3 4 𝑛

6. S=1 + (1*2) + (1*2*3) + ………..(1*2*3*n)

1 2 3 10
7. S= + + +⋯
√1 √2 √3 √10

𝑎2 𝑎2 𝑎2 𝑎2
8. 𝑠 = 𝑎2 + + + +⋯
2 3 4 10

𝑎2 𝑎3 𝑎10
9. 𝑠 = a + + +⋯
2 3 10

12 22 33
10. 𝑠 = + 2
+ + ⋯ 𝑡𝑜 𝑛 𝑡𝑒𝑟𝑚𝑠
𝑎 𝑎 𝑎3

12 32 52
11. 𝑠 = + 2
+ … 𝑡𝑜 𝑛 𝑡𝑒𝑟𝑚𝑠
𝑎 𝑎 𝑎3

𝑎 𝑎 𝑎 𝑎 a
12. 𝑠 = + + + …+
2 5 8 11 20

13. S= 2 - 4 + 6 - 8+ …… -20

14. S= 1 + 4 + 9+ ………400

15. S= (a*2) + (a*3) + ………..(a*20)

x x x x x
16. S = + + + + …… +
2 5 8 11 20

17. s=a1/1 + a2/4 + a3/9 + a4/16 + … to n terms

18. S = 12/a + 32 / a2 + 52 / a3 + …… to n terms

19. s=1!+2!+3!+….+n!
20. s=x/1+x/2+x/3+x/4+…..x/n

III)Write the program in java to display the n terms of following series.

1. 1,4,9,16,…………………………….
2. 1,2,4,7,11,………………………
3. 3,6,9,12,…………………………..
4. 4,8,16,32,…………………………..
5. 1.5,3.0,4.5,6.0,…………………
6. 0,7,26,……………….
7. 1,9,25,49,…………………… .
8. 4,16,36,64,………………. .
9. 0,3,8,15,……….. .
10. 24,99,224,399………….. .
11. 2,5,10,17……………………. .
12. 1,-3,5,-7……………n terms
13.

IV)Programs : Iterartive constructs in java


1 1 5 4 3 2 1
1 2 2 2 5 4 3 2
1 2 3 3 3 3 5 4 3
1 2 3 4 4 4 4 4 5 4
1 2 3 4 5 5 5 5 5 5 5

5 1 2 3 4 5
5 4 3 2 1 5 4 1 2 3 4
4 3 2 1 5 4 3 1 2 3
3 2 1 5 4 3 2 1 2
2 1 5 4 3 2 1 1
1

A A B C D E F
A B B A B C D E
A B C C C A B C D
A B C D D D D A B C
A B C D E E E E E A B
A B C D E F F F F F F A
A B C D E F
5 5 5 5 5 1 1 3 5 7 9
4 4 4 4 4 2 1 1 3 5 7
3 3 3 3 3 3 2 1 1 3 5
2 2 2 2 2 4 3 2 1 1 3
1 1 1 1 1 5 4 3 2 1 1

9 9 9 9 9 9 9
7 7 7 7 7 7 9 9 7
5 5 5 5 5 5 7 9 9 7 5
3 3 3 3 3 3 5 7 9 9 7 5 3
1 1 1 1 1 1 3 5 7 9 9 7 5 3 1

1 * * * * 1 * * * * *
* 2 * * * 2 2 * * * * #
* * 3 * * 3 3 3 * * * # *
* * * 4 * 4 4 4 4 * * # * #
* * * * 5 5 5 5 5 5 * # * # *

* * * * * 5 1 2 3 4 5
* * * * * 4 1 2 3 4
# # # * * 3 1 2 3
* * * * * 2 1 2
# # # # # 1 1
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2
2 3 44
4 5 6
7 8 9 10
666
11 12 13 14 8888
15 16 17 18 19 10 10 10 10 10

You might also like