Class 11 ISC Java Programs Large Text
Class 11 ISC Java Programs Large Text
The PerfectCheck class defines a number as "perfect" if the sum of its digits equals the product of its digits. It calculates both by iterating through the digits of the number with modulo and division operations and compares the sum and product. If they match, it prints "Perfect Number"; otherwise, "Not Perfect Number." This criteria is specific and not in line with traditional perfect number definitions .
The NameSort class sorts an array of five names in descending order by using a nested loop with the `compareTo` method. It swaps adjacent elements if they are in incorrect order (i.e., if `name[j].compareTo(name[j+1]) < 0`) using the bubble sort technique, resulting in a list sorted from highest to lowest lexicographically .
The NameSort class employs a bubble sort algorithm, effective for small datasets like the fixed array of five names but inefficient for larger datasets due to its O(n²) complexity. It assumes a consistent number of inputs, doesn't handle varying input sizes, and presumes lexicographic comparison suffices for all string data, not accounting for locale-specific rules like accented characters or culturally dependent name ordering .
The MatrixOperations class performs several operations on a square matrix: sorting rows in ascending order, columns in descending order, sorting the main diagonal in ascending order, and sorting the anti-diagonal in descending order. The result is a modified matrix where each row is sorted in ascending order, columns in descending order, and diagonals according to the specified criteria .
The ReverseNumber class implements recursion to reverse an integer by continuously shifting existing digits and appending the last digit of the remaining number, recursively repeating this until there are no digits left. A potential drawback is that this recursive approach might lead to a stack overflow for very large numbers due to excessive recursion depth .
The use of `equalsIgnoreCase` for palindrome checking allows the program to recognize palindromes regardless of letter casing, increasing flexibility and usability for the user. This ensures that mixed-case palindromes, like 'Racecar', are correctly identified, enhancing the robustness of the palindrome detection logic .
The bubble sort method used for sorting rows and columns in the MatrixOperations class is inefficient for larger matrices due to its O(n²) complexity for each sorting pass. This results in high computational costs, especially for large matrices, as each row and column require separate sorting passes, making it suboptimal for scenarios needing high performance .
The code checks if a word is a palindrome by reversing the word and comparing it with the original. It uses the `isPalindrome` method, which iterates backward through the word to create a reversed version, then compares the reversed string with the original using `equalsIgnoreCase` to handle case-sensitivity .
The recursive implementation appends the last digit to a reversed number by progressively reducing the original number until it reaches zero, ensuring correct placement of digits by building the reversed number from the least significant digit. Challenges with this method include managing stack depth limits and handling large integers that could result in integer overflow or excessive recursion depth .
The SquareSum class calculates the sum of the squares of digits by iterating over each digit of the number using modulo (`%`) to extract the last digit, squaring it, and adding it to a sum total. The loop continues until all digits have been processed. This method assumes the input number is non-negative, as it does not handle negative numbers .