Answer to Question #286909 in Java | JSP | JSF for Ace

Question #286909

Write a program to create an array to store 30 numbers and then display those numbers in one column and display the message positive or negative in another column. (If 0 then neutral will be displayed)


1
Expert's answer
2022-01-13T07:47:03-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[30];
		for (int i = 0; i < 30; i++) {
			System.out.print("Enter the number " + (i + 1) + ": ");
			numbers[i] = keyBoard.nextInt();
		}


		for (int i = 0; i < 30; i++) {
			String result = "neutral";
			if (numbers[i] > 0) {
				result = "positive";
			}
			if (numbers[i] < 0) {
				result = "negative";
			}
			System.out.printf("%-15d%s\n", numbers[i], result);
		}
		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