Skip to content

uakp98/Java-Coding-Practice-Assignment--Training-Materials

Repository files navigation

Java-Coding-Practice-Assignment--Training-Materials

Java Coding Practice Assignments (Topic: Conditional Statement)

  1. Take two int values from user and print greatest among them.
  2. Take three int values from user and print greatest among them.
  3. Write a Java program to get a number from the user and print whether it is positive or negative.
  4. 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)
  5. Take one int value from user and print if it’s Even or Odd no. (using if-else and Switch case)
  6. Take values of length and breadth of a rectangle from user and check if it is square or not.
  7. 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.)
  8. Write a Java program to find the number of days in a month
  9. Create a calculator by using if-else statement and Switch case
  10. 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.
  11. 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.
  12. 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)
  13. Take input of age of 3 people by user and determine oldest and youngest among them.
  14. 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.
  15. 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.
  16. 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
  17. 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)
  18. 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.


Java Coding Practice Assignment (Topic: Looping Statement)

  1. Write a program which prints the even numbers between 1 and 100 in an increasing order
  2. Take 10 integers from keyboard using loop and print their average value on the screen.
  3. Calculate the sum of digits of a number given by user. E.g.-
    INUPT : 123 OUPUT : 6
    INUPT : 12345 OUPUT : 15
  4. 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.
  5. 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)
  6. Write a program which reads a positive number N from the user then indicates if N is prime or not.
  7. Write a program to print all prime number in between 1 to 100.
  8. Write a program which reads an integer n and displays the n-th Fibonacci number.
  9. Write a program which displays a string with a space after each character.
    (Ex.- abcd -> a b c d)
  10. Write a program which displays the reverse of a String. (Ex.- abcd -> dcba)
  11. 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.
  12. Write a program which finds if a String is a Palindrome String or not.
  13. 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.
  14. Draw a 10*10 multiplication table using For loop.
  15. Print multiplication table of 24, 50 and 29 using loop.
  16. 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.
  17. Print the following patterns using loop :
    There are some pattern problems. click here to see

Best Pattern Questions in Java (Begineers and Advanced level)

  1. Solid Rectangle & Nested Loops -
  2. Hollow Rectangle -
  3. Half Pyramid -
  4. Inverted half Pyramid -
  5. Inverted & Rotated Half Pyramid -
  6. Half Pyramid with Numbers -
  7. Inverted Half Pyramid with Numbers -
  8. Floyd's Triangle -
  9. 0-1 Triangle -