Java interview programming questions
Programs on “Iterative” statement:
Example: 5698
Programs
– Category A:
- Write a program to accept two numbers from the user and find their sum and average.
- Write a program to accept a number from the user and find the cube of that number (to the power 3).
- Write a program to find the simple interest based on the following data: P = Rs 6000, R = 10%, T = 1.5 years.
- Write a program to accept two numbers from the user and swap their values. (Example: x=12, y=15; after swapping x=15, y=12)
- Write a program to accept the weight of 5 persons (one by one) and display the net weight and the average weight.
Programs
on “If”
statement:
- Write a program to accept a number from the user. If the number is negative then convert it to a positive number and print; if it is a positive number, print it as is.
- Write a program to accept the bill amount and age of the customer; if the customer’s age is >50 years then give a discount of 5% on the bill.
- Write a program to accept a number and find whether it is even or odd.
- Write a program to accept two numbers from the user and find the bigger of the two.
- Write a program to accept three numbers and find the biggest number.
- If cost price and selling price of an item is input through the keyboard, write a program to determine whether the seller has made a profit or incurred a loss. Also determine the quantum of profit or loss.
- Write a program to accept any character from the user; determine whether it is – a letter in the upper case, lower case, digit, or a special symbol. (Hint: Use ASCII values.)
Programs on “Iterative” statement:
- Write a program to accept a number from the user and print its multiplication table (upto “times 10”).
- Write a program to accept a number and find the factorial of the number.
- Write a program to accept a number,calculate the sum of all even numbers from 0 till the given number; similarly repeat the same for the odd numbers; then display these two sums. (Example: input number 6; sum of even numbers = 0+2+4+6 =12, sum of odd numbers = 1+3+5 = 9)
- Write a program to accept a number from the user; display the natural number series for the entered number (1,2,3,4,…,N) and calculate the sum of this series.
- Write a program to accept a number and determine whether it is a prime number or not.
- Write a program to print the Fibonacci series up to the number 34. (Example: 0,1,1,2,3,5,8,13,…Series starts with 0 and 1, the succeeding numbers of the series are arrived by adding the previous 2 numbers.)
- Write a program to accept a number “n” from the user; then display the sum of the series 1+1/2+1/3+……….+1/n.
- Write a program to accept a number “n” from the user; then display the series 1,3,5,7,9,…,n and find the sum of the numbers in this series.
- Write a program to print the following output.
1
2
3
4
5 6 7
8
9 10 11
- Write a program to print the following output.
*
*
*
*
* *
*
* * *
*
* * * *
- Write a program to print the following output.
*
*
* *
* * * * *
* * * * * * *
* * * * * * * * *
- Write a program to print the following output.
1
121
12321
1234321
123454321
- Write a program to print the following output.
19 0 0
0 19 0
0 0 19
- Write a program to accept a number “n” from the user; find the sum of the series 1/23+1/33+1/43……..+1/n3.
Programs
on “Iterative”
statement:
- Write a program to accept a number from the user and find the sum of digits in the given number.
- Write a program to accept a number from the user and find the reverse of the given number.
- Write a program to accept a number from the user and determine whether it is an Armstrong number or not (Example : 153 is Armstrong 1^3 + 5 ^3 +3 ^3 =153)
- Write a program to accept a number from the user and find the sum of digits of the number; repeat the operation till the sum gets to be a single digit number.
- Write a program to accept a number from the user and find the count of the digits that are prime numbers.
- Write a program to accept a number and find the factorial of the number (using while loop).
- Write a program to accept a four digit number from the user and display its denomination.
Example: 5698
Output:
5*1000 =5000
6*100
=600
9*10
=90
8*1
=8
- Write a program to accept a five digit number and increment each digit by one and display the number (digit 9 gets incremented to 0).
Example:
Input:
14385
Output: 25496
- Write a program to accept 2 numbers “m” and “n” from the user and determine m^n (without using predefined functions).
No comments:
Post a Comment