Answer to Question #286461 in Java | JSP | JSF for -----

Question #286461

Write a program in Java to store 30 numbers in an array then display those numbers in descending order with a condition that maximum 5 numbers will appear in one line.

1
Expert's answer
2022-01-10T17:31:19-0500
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int[] array = new int[11];
        for (int i = 0; i < array.length; i++) {
            array[i] = in.nextInt();
        }
        Arrays.sort(array);
        for (int i = array.length - 1, j = 1; i >= 0; i--, j++) {
            System.out.print(array[i] + " ");
            if (j % 5 == 0) {
                System.out.println();
            }
        }
    }
}

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