You are on page 1of 2

Dr.

Virendra Swarup Public School, Cantt


Computer Applications
Iterations in Java
Write the Output:
Q1 while(++i<6)
x = 5; y = 50; k*=i;
while(x<=y) System.out.println(k);
{ Q4
y = y/x; int a,b;
System.out.println(y); for(a=6, b=4; a<=4; a=a+6 )
} {
Q2 if(a%b==0)
int m = 2; break;
int a = 15; System.out.println(a);
for(int i=1; i<5; i++) }
m++; Q5
n--; int i;
System.out.println(“m=”+m); for(i=5; i>10; i++)
System.out.println(“n=”+n); System.out.println(i);
Q3 System.out.println(i*4);
Int k=1, i=2;
Programs:
1. Write the programs in programs in Java to display the first ten terms of the following series:
(a) 0, 1, 2, 3, 6,
(b) 1, -3, 5, -7, 9,
(c) 0, 3, 8, 15,
(d) 1, 11, 111, 1111,
(e) 1, 12, 123, 1234,
2. Write the programs in Java to find the sum of the following series:
(a) S = 1 + 1 + 2 + 3 + 5 +………… to n terms
(b) S = 2 – 4 + 6 – 8 +………… to n
(c) S = 1 + (1 + 2) + (1 + 2 + 3) + ………… + (1+2+3+………+n)
(d) S = 1 + (1 * 2) + (1 * 2 * 3) + ………… + (1*2*3*………*n)
3. Write the programs to find the sum of the following series:
(a) S = a + a2 + a3 + …………… + an
(b) S = (a+1) + (a+2) + (a+3) + …………… + (a+n)
(c) S = (a/2) + (a/5) + (a/8) + (a/11) + …………… + (a/20)
(d) S = a - a3 + a5 - a7 + …………… to n
4. Write a programs to input a number and find the number is Armstrong or not.
Sample Input: 153
Sample Output: 153 = 13 + 53 + 33
It is an Armstrong Number
5. Write a program to accept a number from the user and check whether it is a Palindrome number or not.
A number is a Palindrome which when reads in reverse order is same as in the right order.
Sample Input: 242
Sample Output: A Palindrome number
Sample Input: 467
Sample Output: A not a Palindrome number
6. Write a program in Java to accept a number. Check and print whether it is a prime number or not. A
prime number is a number which is divisible by 1 and itself only. For example: 2, 3, 5, 7, 11,13 are all prime
numbers.
7. 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.
8. Write a program to enter two numbers and check whether they are co-prime or not.
[Two numbers are said to be co-prime, if their HCF is 1 (one).]
Sample Input: 14, 15
Sample Output: They are co-prime.
9. Write a program to input a number. Display the product of the successors of even digits of the number
entered by user.
Sample Input: 2745
Sample Output: 15
[Hint: The even digits are: 2 and 4
The product of successors of even digits is: 3*5= 15]
10. Write a program to input a number and check and print whether it is Pronic number or not
[Pronic number is the number which is the product of two consecutive integers.]
Examples:
12 = 3*4
20 = 4*5
42 = 6*7
11. Write a program to input a number and check whether it is a prime number or not. If it is not a prime
number then display the next number that is prime.
Sample Input: 14
Sample Output: 17
12. 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.
13. 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”.
14. Write a program to input a number. Check and display 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
16. Using a switch Statement, write a menu driven program to:
(a) Generate and display the first 10 terms of the Fibonacci series
0, 1, 1, 2, 3, 5
The first two Fibonacci number are 0 and 1, and each subsequent number is the sum of the previous two.
(b) find the sum of the digits of an integer that is input by the user.
Sample Input: 15390
Sample Output: Sum of the digits = 18
For an incorrect choice, an appropriate error message should be displayed.s

You might also like