- Take two int values from user and print greatest among them.
- Take three int values from user and print greatest among them.
- Write a Java program to get a number from the user and print whether it is positive or negative.
- Take an input value from user and check the status of grade in the following order-
(If the percentage is above 90, assign grade ‘A+’, If the percentage is above 75, assign grade ‘A’, If the percentage is above 65, assign grade ‘B+’, If the percentage is above 50, assign grade ‘B’, If the percentage is above 35, assign grade ‘C’, Below 35, Fail) - Take one int value from user and print if it’s Even or Odd no. (using if-else and Switch case)
- Take values of length and breadth of a rectangle from user and check if it is square or not.
- Write a program to check if a year is leap year or not.
(If a year is divisible by 4 then it is leap year but if the year is century year like 2000, 1900, 2100 then it must be divisible by 400.) - Write a Java program to find the number of days in a month
- Create a calculator by using if-else statement and Switch case
- A shop will give discount of 10% if the cost of purchased quantity is more than 1000.
Ask user for quantity
Suppose, one unit will cost 100.
Judge and print total cost for user. - A company decided to give bonus of 5% to employee if his/her year of service is more than 5 years. Ask user for their salary and year of service and print the net bonus amount.
- A school has following rules for grading system:
a. Below 25 - F
b. 25 to 45 - E
c. 45 to 50 - D
d. 50 to 60 - C
e. 60 to 80 - B
f. Above 80 - A
Ask user to enter marks and print the corresponding grade. (using Switch case only) - Take input of age of 3 people by user and determine oldest and youngest among them.
- A student will not be allowed to sit in exam if his/her attendance is less than 75%.
Take following input from user
Number of classes held
Number of classes attended.
And print
percentage of class attended
Is student is allowed to sit in exam or not. - Modify the above question to allow student to sit if he/she has medical cause. Ask user if he/she has medical cause or not (‘Y' or 'N’) and print accordingly.
- A 4-digit number is entered through keyboard. Write a program to print a new number with digits reversed as of original one. E.g.-
INPUT: 1234 OUTPUT: 4321
INPUT: 5982 OUTPUT: 2895 - A four digit number ABCD is called Lucky number if A+B=C+D
(Example- 3719 is a Lucky number as 3+7=1+9 but 3521 is not a Lucky Number as 3+5 != 1+9) - Write a Java program that takes the user to provide a single character from the alphabet. Print Vowel or Consonant, depending on the user input. If the user input is not a letter (between a and z or A and Z), or is a string of length > 1, print an error message.
- Write a program which prints the even numbers between 1 and 100 in an increasing order
- Take 10 integers from keyboard using loop and print their average value on the screen.
- Calculate the sum of digits of a number given by user. E.g.-
INUPT : 123 OUPUT : 6
INUPT : 12345 OUPUT : 15 - Write a program which reads a sequence of integers from the user and stop by displaying “Done” when the sum of these values exceeds 100.
- Write a program which displays the sum of the strict divisors of an integer given by the user.
(Ex.- input-6 ->divisors of 6 are 1,2,3 ; by adding them we can get 1+2+3=6 ;So 6 will be the output
input-10 ->divisors of 6 are 1,2,5 ; by adding them we can get 1+2+5=8 ;So 8 will be the output) - Write a program which reads a positive number N from the user then indicates if N is prime or not.
- Write a program to print all prime number in between 1 to 100.
- Write a program which reads an integer n and displays the n-th Fibonacci number.
- Write a program which displays a string with a space after each character.
(Ex.- abcd -> a b c d) - Write a program which displays the reverse of a String. (Ex.- abcd -> dcba)
- Factorial of any number n is represented by n! and is equal to 1*2*3*....*(n-1)*n.
E.g.-
4! = 1*2*3*4 = 24
3! = 3*2*1 = 6
2! = 2*1 = 2
Also,
1! = 1
0! = 0
Write a Java program to calculate factorial of a number. - Write a program which finds if a String is a Palindrome String or not.
- A three digit number is called Armstrong number if sum of cube of its digit is equal to number itself.
E.g.- 153 is an Armstrong number because (13)+(53)+(33) = 153.
Write all Armstrong numbers between 100 to 500. - Draw a 10*10 multiplication table using For loop.
- Print multiplication table of 24, 50 and 29 using loop.
- Take integer inputs from user until he/she presses q ( Ask to press q to quit after every integer input ). Print average and product of all numbers.
- Print the following patterns using loop :
There are some pattern problems. click here to see
- Solid Rectangle & Nested Loops -
- Hollow Rectangle -
- Half Pyramid -
- Inverted half Pyramid -
- Inverted & Rotated Half Pyramid -
- Half Pyramid with Numbers -
- Inverted Half Pyramid with Numbers -
- Floyd's Triangle -
- 0-1 Triangle -