Nice day to all... I'm new in java programming and I'm having some problem with this program. The problem is this: Write a program that will read an unspecified number of non-zero integers and determine how many positive and negative values have been read. The program will abort when the user input a zero.
I've already made a program but I still can't get it right. I deeply appreciate if you will help me.
Here's the program I made:
import javax.swing.JOptionPane;
public class counter
{
public static void main(String [] args)
{
String num;
int count;
int number;
count = 0;
number = 0;
num = JOptionPane.showInputDialog(null, "Enter your first integer:");
int inputNumber = Integer.parseInt(num);
while (inputNumber!=0)
{
if (inputNumber > 0)
count ++;
else
number ++;
num = JOptionPane.showInputDialog(null, "Enter another integer, or enter 0 to end:");
}
if (count == 0)
{
JOptionPane.showMessageDialog(null, "Program aborting.");
}
else
{
JOptionPane.showMessageDialog(null, "There are " + count + " positive integers." );
JOptionPane.showMessageDialog(null, "There are " + number + " negative integers." );
}
}
}