Java Program to sort the elements of an array in descending order17 Mar 2025 | 2 min read In this program, we need to sort the given array in descending order such that elements will be arranged from largest to smallest. This can be achieved through two loops. The outer loop will select an element, and inner loop allows us to compare selected element with rest of the elements. ![]() Elements will be sorted in such a way that largest element will appear on extreme left which in this case is 8. The smallest element will appear on extreme right which in this case is 1. Algorithm
Program:Output: Elements of original array: 5 2 8 7 1 Elements of array sorted in descending order: 8 7 5 2 1 Next TopicJava Programs |
An array of unsorted integers is given. Our task is to move all the zero elements to the end and non-zero elements to the front. Note the relative arrangement of the non-zero elements should never get disturbed. The following examples make things clearer. Example 1: Input: int arr[]...
6 min read
Java Convert Binary to Decimal We can convert binary to decimal in java using Integer.parseInt() method or custom logic. Java Binary to Decimal conversion: Integer.parseInt() The Integer.parseInt() method converts string to int with given redix. The signature of parseInt() method is given below: public static int parseInt(String s,int redix) Let's see...
2 min read
Java Program Number to Word In this section, we will create a Java program that converts the given number into words. For example, if the given number is 54,297 then the output should be Fifty-Four Thousand Two Hundred Ninety-Seven. Let's create a Java program for the same. NumberToWordExample1.java class...
9 min read
Java program to print the following pattern Algorithm: STEP 1: START STEP 2: SET i=1,j=1,k=1,l=1,direction=1 STEP 3: SET matrix[5][5] STEP 4: REPEAT STEP 5 to 9 UNTIL i is less than 5 STEP 5: SET j=0 STEP 6: REPEAT STEP 7 and 8 UNTIL j is less than 5 STEP 7: SET matrix[i][j]=0 STEP...
11 min read
. In this program, we need to count each character present in the string and find out the maximum and minimum occurring character. Grass is greener on the other side In above example, character 'a' is occurred only once in the string. So, it is minimum occurring character...
5 min read
Java Program to find the frequency of odd & even numbers in the given matrix In this program, we need to find the frequencies of odd and even numbers present in the matrix. In the above example, all odd numbers are represented by the blue square and...
3 min read
Palindromes are fascinating linguistic constructs that have intrigued minds for centuries. In simple terms, a palindrome is a word, phrase, number, or other sequences of characters that reads the same forward and backward. In the realm of programming, creating a program to determine whether a...
9 min read
In this program, we need to multiply two matrices and print the resulting matrix. Product of two matrices The product of two matrices can be computed by multiplying elements of the first row of the first matrix with the first column of the second matrix then, add...
6 min read
In this program, we will create a doubly linked list and sort nodes of the list in ascending order. Original List: Sorted List: To accomplish this, we maintain two pointers: current and index. Initially, current point to head node and index will point to node to current....
7 min read
In this program, we need to count the number of characters present in the string: The best of both worlds To count the number of characters present in the string, we will iterate through the string and count the characters. In above example, total numbers of characters...
2 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India