Answer to Question #286340 in Java | JSP | JSF for Second

Question #286340

Write a program to store 25 numbers in an array. Then display those numbers divisible by 5 only in descending order using bubble sorting & also display how many such numbers found.


1
Expert's answer
2022-01-11T11:06:43-0500


import java.util.Scanner;


public class App {


	/**
	 * The start point of the program
	 * 
	 * @param args
	 * 
	 */
	public static void main(String[] args) {
		Scanner keyBoard = new Scanner(System.in);


		int numbers[] = new int[25];
		for (int i = 0; i < 25; i++) {
			System.out.print("Enter the number " + (i + 1) + ": ");
			numbers[i] = keyBoard.nextInt();
		}
		bubbleSort(numbers);
		int counter = 0;
		System.out.println("\nAll numbers divisible by 5 in descending order:");
		for (int i = 0; i < 25; i++) {


			if (numbers[i] % 5 == 0) {
				System.out.print(numbers[i] + " ");
				counter++;
			}
		}
		System.out.println("\nThe number of divisible by 5: " + counter);


		keyBoard.close();
	}


	static void bubbleSort(int numbers[]) {
		int n = numbers.length;
		for (int i = 0; i < n - 1; i++)
			for (int j = 0; j < n - i - 1; j++)
				if (numbers[j] < numbers[j + 1]) {
					int temp = numbers[j];
					numbers[j] = numbers[j + 1];
					numbers[j + 1] = temp;
				}
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog