Answer to Question #285993 in Java | JSP | JSF for Michael

Question #285993

Write a program to store 15 numbers in an array. Then display all negative numbers in ascending order using sorting.


1
Expert's answer
2022-01-09T03:08:36-0500


import java.util.Arrays;
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[15];
		for (int i = 0; i < 15; i++) {
			System.out.print("Enter the number " + (i + 1) + ": ");
			numbers[i] = keyBoard.nextInt();
		}
		Arrays.sort(numbers);
		int counter = 0;
		System.out.println("\nAll negative numbers in ascending order");
		for (int i = 0; i < 15; i++) {
			if (numbers[i] <0) {
				System.out.print(numbers[i] + " ");
				counter++;
			}
		}
		System.out.println("\nThe number of negative values: " + counter);
		keyBoard.close();
	}
}

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