Skip to content

This is a Java Practice Solution Repository where there are set of Problem solved and saved in it.

Notifications You must be signed in to change notification settings

ROSHAN-KHANDAGALE/Programs-Java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

76 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JAVA Questions

Loops

  1. Print Numbers: Write a program to print numbers from 1 to 10 using a for loop. ✅
  2. Even Numbers: Print even numbers between 1 and 20 using a for loop. ✅
  3. Odd Numbers: Print odd numbers between 1 and 20 using a while loop. ✅
  4. Sum of Numbers: Calculate the sum of numbers from 1 to 100 using a for loop. ✅
  5. Factorial: Calculate the factorial of a number using a while loop. ✅
  6. Fibonacci Series: Generate Fibonacci series up to n terms using a for loop. ✅
  7. Reverse Number: Reverse a given number using a while loop.
  8. Palindrome Number: Check if a given number is a palindrome using a while loop.
  9. Prime Numbers: Print prime numbers up to n using nested for loops.
  10. Armstrong Number: Check if a number is an Armstrong number using a for loop.
  11. Sum of Digits: Calculate the sum of digits of a number using a while loop. ✅

Arrays

  1. Copy Array: Copy the elements of one array into another array. ✅
  2. Sum of Array Elements: Write a program to calculate the sum of all elements in an array. ✅
  3. Average of Array Elements: Calculate the average of elements in an array. ✅
  4. Largest Element in Array: Find the largest element in an array. ✅
  5. Smallest Element in Array: Find the smallest element in an array. ✅
  6. Search Element in Array: Search for a specific element in an array and print its index if found. ✅
  7. Reverse Array: Reverse the elements of an array. ✅
  8. Duplicate Elements in Array: Print the Duplicate elements of an array. ✅
  9. Sort Duplicate Elements: Remove Duplicate Element in an array. ✅
  10. Sorting in Ascending Order: Sort the elements of an array in Ascending order. ✅
  11. Sorting in Descending Order: Sort the elements of an array in Descending order. ✅
  12. Total Elements in Array: Print the number of elements in an array. ✅
  13. Odd Even Elements: Print Odd and Even Numbers from an array. ✅
  14. Left Rotate Elements in Array: Java Program to the left rotate the elements of an array. ✅
  15. Right Rotate Elements in Array: Java Program to right rotate the elements of an array. ✅
  16. Shift Index Ascending: Java Program to Sort the elements of an array in Ascending order from a specific Index. ✅
  17. Shift Index Descending: Java Program to Sort the elements of an array in Descending order from a specific Index. ✅
  18. User Defined Array: Java Program to create a user Defined Array. ✅
  19. Total Length and Present Element: Java Program to Insert Elements in an Array and Print its Elements and Length. ✅
  20. Add Element at First Index: Program to add Element at First Index of an Array. ✅
  21. Add Element at Last Index: Program to add Element at Last Index of an Array. ✅
  22. Add Element at given Index: Program to add Element at a given Index of an Array. ✅

Matrix

  1. Addition of Array: To Add two Dimensional array.
  2. Subtraction of Array: To Subtract two Dimensional array.
  3. Multiplication of Array: To Multiply two Dimensional array.
  4. Division of Array: To Divide two Dimensional array.

Strings

  1. Count Total Character: Program to Calculate the Total Number of Characters in a String. ✅
  2. Count Punctuation: Java Program to count the total number of punctuation characters exists in a String. ✅
  3. Count Vowels and Consonants: Java Program to count the total number of vowels and consonants in a String. ✅
  4. Anagram of Strings: Java Program to determine whether two strings are the anagram. ✅
  5. Replace Spaces to Characters: Java Program to replace the spaces of a string with a specific character. ✅
  6. Reverse of String: Java Program to find Reverse of the string. ✅

EXTRA PROBLEM-SOLVING

  1. FIZZBUZZ PROBLEM
    Given a number n, for each integer i in the range
    from i to n inclusive, print one value per line as
    follows:
     • If i is a multiple of both 3 and 5, print FizzBuzz.
     • If i is a multiple of 3(but not 5), print Fizz.
     • If i is a multiple of 5(but not 3), print Buzz.
     • If i is not a multiple of 3 or 5, print the value of i.

    Function Description:
    Complete the function fizzBuzz in the editor below.

    fizzBuzz has the following parameter(s):
    int n: upper limit of values to test (inclusive)
    Returns: NONE
    Prints:
    The function must print the appropriate response for each value i in the set {1, 2, ... n} in
    ascending order, each on a separate line.

    Constraints:
     • 0 < n < 2x105


    EXPECTED OUTPUT :
    Expected Output


    Explanation:
    The numbers 3, 6, 9, and 12 are multiples of 3(but not 5), so print Fizz on those lines. The numbers 5 and 10 are multiples of 5(but not 3), so print Buzz on those lines. The number 15 is a multiple of both 3 and 5, so print FizzBuzz on that line. None of the other values is a multiple of either 3 or 5, so print the value of i on those lines.


  2. LECTURE Question

    A new Chemistry teacher is very strict and wants
    the students to do well in class. To aid this, lectures
    on each chapter will be repeated periodically
    through the semester. In each class, the next
    chapter is presented. When they reach the end of
    the book, the lectures start over with chapter 0.
    More formally, if there are numChapters in the
    book, then on the day, the lecture will be on
    chapter i%numChapters. The first day of class is
    class[0], and the first chapter is chapter 0. If there
    are 3 chapters, daily lectures are on chapters class
    = [0, 1, 2, 0, 1, 2, ...1. At class[4], the lecture will be
    on chapter 4%3 = 1.

    One of the students is going to be out of class for a
    wedding, and the teacher is concerned about
    missed lectures. Given the first and last days the
    student will be out, determine the number of
    chapters for which the student will miss lectures.
    For example, there are numChapters = 4 chapters
    in the book. The student is out of class beginning
    on day b =3through ending day e = 5. The series
    of lectures are on chapters class = [0, 1, 2, 3, 0, 1, 2, 3,..]
    starting from day 0. For class[3] through
    class[5], lectures are given on chapters 3, O and 1.
    The student will miss lectures on 3 chapters.


    Function Description:
    Complete the function missedLectures in the editor below. The function must return an integer.

    • missedLectures has the following parameters:
    • numChapters: an integer
    • b: an integer
    • e: an integer

    Constrains

    • 1 <= numChapters <= 109
    • 1 <= b <= e <= 109

    Sample Input For Custom Testing
    5
    5
    6

    Sample Output
    2

    Explanation
    Chapters are taught in the order class = [0, 1, 2, 3, 4, 0, 1, 2, 3, 4] The student will miss chapters 0 and 1 on days 5 and 6 respectively.