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)
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();
}
}
Comments
Leave a comment