Java Programming Practice

General Java Programs

A structured, easy-to-navigate HTML version of the supplied practice sheet, preserving the original program sequence and the star-pattern exercises without embedding the original PDF pages.

120 Programs 10-page source document Prepared by Srikanth Mamillapalli Java Fundamentals Practice
1–28

1–28. Number & Basic Math

  1. 1. WAP for area of Triangle (1/2 × a × b).
  2. 2. WAP for area of Rectangle.
  3. 3. WAP for area of Circle.
  4. 4. WAP for area of Square.
  5. 5. WAP for area of Rhombus.
  6. 6. WAP for area of Polygon.
  7. 7. WAP for Factorial of a given number.
  8. 8. WAP for first 20 factorial numbers (0 to 20).
  9. 9. WAP for Fibonacci series.
  10. 10. WAP for reverse of a given number. Example: 531 → 135.
  11. 11. WAP to check whether a given number is a palindrome or not.
  12. 12. WAP to check whether a given number is a perfect number or not.
  13. 13. WAP to check whether a given number is a strong number or not.
  14. 14. WAP to check whether a given number is a prime number or not.
  15. 15. WAP to check whether a given number is an Armstrong number or not. Example: 153 = 1 + 125 + 27 = 153.
  16. 16. WAP to find the first 1000 perfect numbers.
  17. 17. WAP to find the first 1000 strong numbers.
  18. 18. WAP to find the first 1000 prime numbers.
  19. 19. WAP to find the first 1000 factorial numbers.
  20. 20. WAP to find the first 1000 palindrome numbers.
  21. 21. WAP for Factorial using Recursion.
  22. 22. WAP for prime number using Recursion.
  23. 23. WAP for perfect number using Recursion.
  24. 24. WAP for strong number using Recursion.
  25. 25. WAP for Fibonacci series using Recursion.
  26. 26. WAP to display individual digits of a given number. Example: 531 → 5, 3, 1.
  27. 27. WAP for multiplication of individual digits of a given number. Example: 420 → 4 × 2 × 0 = 0.
  28. 28. WAP for sum of individual digits of a given number. Example: 531 → 5 + 3 + 1 = 9.
29–57

29–57. Operators, Conditions & Loops

  1. 29. WAP for largest of 2 numbers.
  2. 30. WAP for largest of 3 numbers.
  3. 31. WAP for largest of 4 numbers.
  4. 32. WAP for largest of 3 numbers using Arithmetic and Relational Operators.
  5. 33. WAP for smallest of 2 numbers.
  6. 34. WAP for smallest of 3 numbers.
  7. 35. WAP for smallest of 4 numbers.
  8. 36. WAP for multiplication table of a given number.
  9. 37. WAP for multiplication table of N-number series. Example: N = 4 → display 1st, 2nd, 3rd and 4th tables.
  10. 38. WAP to check whether a given number is even or not.
  11. 39. WAP to check whether a given number is odd or not.
  12. 40. WAP to check whether a given number is even without using if.
  13. 41. WAP to check whether a given number is even using the ternary operator.
  14. 42. WAP to check whether a given number is even using switch.
  15. 43. WAP for sum of even number series.
  16. 44. WAP for sum of odd number series.
  17. 45. WAP for sum of N-number series.
  18. 46. WAP for swapping of 2 numbers.
  19. 47. WAP for swapping of 2 numbers without a temporary variable.
  20. 48. WAP for swapping of 2 numbers with a single statement.
  21. 49. WAP using for loop to display 1 to 10 numbers.
  22. 50. WAP using for loop to display 10 to 1 numbers.
  23. 51. WAP using while loop to display 1 to 10 numbers.
  24. 52. WAP using while loop to display 10 to 1 numbers.
  25. 53. WAP using do-while loop to display 1 to 10 numbers.
  26. 54. WAP using do-while loop to display 10 to 1 numbers.
  27. 55. WAP for sum series: 1 + 2 + 3 + … + n = n(n + 1)/2.
  28. 56. WAP for sum series: 1² + 2² + 3² + … + n² = n(n + 1)(2n + 1)/6.
  29. 57. WAP for sum series: 1³ + 2³ + 3³ + … + n³ = n²(n + 1)²/4.
58–69

58–69. Series, Functions & Patterns

  1. 58. WAP to check whether a, a+d, a+2d, a+3d, … are in A.P. Find nth term = a + (n−1)d and sum of n terms = (n/2)(2a + (n−1)d).
  2. 59. WAP to check a, ar, ar², … as a G.P. Find the nth term.
  3. 60. WAP for powers function without using pow() function.
  4. 61. WAP to find nPr value.
  5. 62. WAP to find nCr value.
  6. 63. WAP for square of a given number.
  7. 64. WAP to print the following output for n = 4: Number / Square / Cube → 1 1 1, 2 4 8, 3 9 27, 4 16 64.
  8. 65. WAP to print the series of numbers divisible by 10 up to 200(n). N should be passed at runtime.
  9. 66. WAP to print the number series from 1 to 7 and 0 to 7. Output: 1,2,3,4,5,6,7 ::: 0,1,2,3,4,5,6,7.
  10. 67. WAP to print the series: 1,2,3,4,5,6,7,6,5,4,3,2,1.
  11. 68. WAP to display the given number pyramid using loops: 1 / 2 3 / 4 5 6 / 7 8 9 10.
  12. 69. WAP to display the descending number pattern: 10 9 8 7 / 6 5 4 / 3 2 / 1.
70–80

70–80. Number & Star Patterns

  1. 70. Star pattern: increasing triangle (1, 2, 3, 4 stars).
  2. 71. Star pattern: decreasing/inverted triangle.
  3. 72. Star pattern: increasing triangle.
  4. 73. Star pattern: increasing triangle up to 4 rows.
  5. 74. Star pattern: increasing triangle up to 5 rows.
  6. 75. Star pattern: decreasing triangle.
  7. 76. Star pattern: mixed/inverted triangle pattern.
  8. 77. Number pattern: 1 2 3 4 5 4 3 2 1.
  9. 78. Number pyramid pattern: 1 1 / 1 2 2 1 / 1 2 3 3 2 1 / 1 2 3 4 4 3 2 1 / 1 2 3 4 5 4 3 2 1.
  10. 79. WAP to reverse numbers using the shown logic: 12 → 21, 144 → 441. Rev(144) = 441. Write the logic of the program.
  11. 80. WAP to find the series based on the above reverse-number logic up to 1000.
81–96

81–96. Numbers, Words, Grade & Conversion

  1. 81. WAP to find the second largest of given numbers.
  2. 82. WAP for a given number such as 896 to print: eight nine six.
  3. 83. WAP to display a given number in words. Example: 120 = One Twenty.
  4. 84. WAP to display a given number in words. Example: 12,531 = Twelve thousand and Five hundred and thirty one.
  5. 85. WAP to display and complete the student-grade program. Variables: Sno, sname, m1, m2, m3. All fields should be non-null, then find the grade.
  6. Grade rules: 75% → Distinction; 60%–74% → I Class; 45%–59% → II Class; 35%–44% → III Class; 0%–34% → Fail.
  7. 86. WAP for LCM of two numbers.
  8. 87. WAP to convert decimal to binary.
  9. 88. WAP to convert binary to decimal.
  10. 89. WAP to convert octal to decimal.
  11. 90. WAP to convert decimal to octal.
  12. 91. WAP to convert hexadecimal to binary.
  13. 92. WAP to convert decimal to hexadecimal.
  14. 93. WAP to find whether a given number is positive, negative or neutral.
  15. 94. WAP to find the power-unit rate. House: 1 unit = ₹3; Shopping complex: 1 unit = ₹14; Software company: 1 unit = ₹24. Display Item, Units and Total Price.
  16. 95. WAP for Pascal Triangle.
  17. 96. WAP for increment operator. Given expression: a=1; a++; ++a; b=(a++)+(++a)+(++a)+(a++)-(a)+(a--)+(a++)+(++a)-(--a)+(++a); System.out.println(b);
97–105

97–105. Arrays

  1. 97. WAP to find/display the elements in an array.
  2. 98. WAP for sum of array elements.
  3. 99. WAP for addition of two arrays.
  4. 100. WAP for subtraction of two arrays.
  5. 101. WAP to find the largest element in an array.
  6. 102. WAP to display elements in a character array.
  7. 103. WAP to find the index value when an element is given in an array.
  8. 104. WAP for sorting an array.
  9. 105. WAP for Bubble Sort.
106–120

106–120. Series, Trigonometry, Matrix & Date

  1. 106. Evaluate the series: 1 + 1/x! + 1/x²! + 1/x³! + …, where n and x are input values.
  2. 107. Evaluate the series: 1 − 1/x! + 1/x²! − 1/x³! + …, where n and x are input values.
  3. 108. WAP using switch to compute arithmetic operations.
  4. 109. WAP to evaluate the SIN(θ) series up to a given θ value in degrees. Also consider sin(), cos(), tan(), cot(), sec(), cosec() for 0°, 30°, 45°, 60° and 90°.
  5. 110. WAP demonstrating break and continue using a for loop: a) if (i == j) continue; b) if (i == j) break.
  6. 111. WAP to check whether a given year is a leap year or not.
  7. 112. WAP to find the leap-year list from 1960 to 2020.
  8. 113. WAP to display matrix elements.
  9. 114. WAP for matrix addition.
  10. 115. WAP for matrix multiplication.
  11. 116. WAP for matrix subtraction.
  12. 117. WAP for matrix division (elements in the matrix should be non-null).
  13. 118. WAP to find the index of a matrix element when the element is given.
  14. 119. WAP to find the element for a given matrix index.
  15. 120. WAP to display the day-of-week name for a given date.

Star Pattern Gallery

The source document shows the visual star-pattern exercises on pages 9–10. They are recreated below as lightweight HTML/CSS previews rather than inserting the original PDF pages.

* * * * * * * * *
* * * * * * * * *
* * * * * * * * *
* * * * * * * * *
* * * * * * * * *
* * * * * * * * *
* * * * * * * * *
* * * * * * * * *
* * * * * * * * *

Square Star Pattern

* * * * * * * * *
* *           * *
*   *       *   *
*     *   *     *
*       *       *
*     *   *     *
*   *       *   *
* *           * *
* * * * * * * * *

Hollow Square Star Pattern with Diagonal

* * * * * * * * *
*               *
*               *
*               *
*               *
*               *
*               *
*               *
* * * * * * * * *

Rhombus Star Pattern

* * * * * * * * *
*               *
*               *
*               *
*               *
*               *
*               *
*               *
* * * * * * * * *

Hollow Rhombus Star Pattern

* * * * * * * * *
*               *
*               *
*               *
*               *
*               *
*               *
*               *
* * * * * * * * *

Mirrored Rhombus Star Pattern

* * * * * * * * *
*               *
*               *
*               *
*               *
*               *
*               *
*               *
* * * * * * * * *

Hollow Mirrored Rhombus Star Pattern

*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *

Right Triangle Star Pattern

                *
              * *
            * * *
          * * * *
        * * * * *
      * * * * * *
    * * * * * * *
  * * * * * * * *
* * * * * * * * *

Mirrored Right Triangle Star Pattern

*
* *
*   *
*     *
*       *
*         *
*           *
*             *
* * * * * * * * *

Hollow Right Triangle Star Pattern

                *
              * *
            *   *
          *     *
        *       *
      *         *
    *           *
  *             *
* * * * * * * * *

Hollow Mirrored Right Triangle Star Pattern

* * * * * * * * *
  *             *
    *           *
      *         *
        *       *
          *     *
            *   *
              * *
                *

Hollow Inverted Mirrored Right Triangle Star Pattern

* * * * * * * * *
*             *
*           *
*         *
*       *
*     *
*   *
* *
*

Hollow Inverted Right Triangle Star Pattern

* * * * * * * * *
* * * * * * * *
* * * * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*

Inverted Right Triangle Star Pattern

* * * * * * * * *
  * * * * * * * *
    * * * * * * *
      * * * * * *
        * * * * *
          * * * *
            * * *
              * *
                *

Inverted Mirrored Right Triangle Star Pattern

* * * * * * * * *
*               *
*               *
*               *
*               *
*               *
*               *
*               *
* * * * * * * * *

Hollow Square Star Pattern

        *
        *
      * * *
      * * *
    * * * * *
    * * * * *
  * * * * * * *
  * * * * * * *
* * * * * * * * *

Pyramid Star Pattern

        *

      *   *

    *       *

  *           *

* * * * * * * * *

Hollow Pyramid Star Pattern

* * * * * * * * *
  * * * * * * *
  * * * * * * *
    * * * * *
    * * * * *
      * * *
      * * *
        *
        *

Inverted Pyramid Star Pattern

* * * * * * * * *

  *           *

    *       *

      *   *

        *

Hollow Inverted Pyramid Star Pattern

          * * * *
        * * * * *
      * * * * * *
    * * * * * * *
  * * * * * * * *
    * * * * * * *
      * * * * * *
        * * * * *
          * * * *

Right Arrow Star Pattern

*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*

Half Diamond Star Pattern

*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*

Left Arrow Star Pattern

        *
        *
        *
        *
* * * * * * * * *
        *
        *
        *
        *

Plus Star Pattern

        *
      * * *
    * * * * *
  * * * * * * *
* * * * * * * * *
  * * * * * * *
    * * * * *
      * * *
        *

Diamond Star Pattern

*               *
  *           *
    *       *
      *   *
        *
      *   *
    *       *
  *           *
*               *

X Star Pattern