All pastes #408914 Raw Edit

JayBachatero

public java v1 · immutable
#408914 ·published 2007-03-25 06:51 UTC
rendered paste body
/** * @author Jeffrey Hernandez * @class: Average */import javax.swing.JOptionPane;public class Average{	public static void main(String[] args)	{		// Set these varibles.		int num, avg, totalInput;		int posCount = 0;		int negCount = 0;		int sum = 0;		String input;		// Save this as a variable since we will be using it again.		String txtInput = "Enter a number to add.  Enter 0 to get the average.";		// Get the number for input.		input = JOptionPane.showInputDialog(txtInput);		num = Integer.parseInt(input);		while (num != 0)		{			// Is it a possitive number?  If so add to the posCounter and to the sum.			if (num > 0)			{				posCount++;				sum += num;			}			else if (num < 0)			{				negCount++;				sum += num;			}			else				num = 0;			// Lets ask for input once more.			input = JOptionPane.showInputDialog(txtInput);			num = Integer.parseInt(input);		}		// Since we finished lets add these numbers.		totalInput = posCount + negCount;		avg = sum / totalInput;		// Say something.		JOptionPane.showMessageDialog(null, "You entered a total of " + totalInput + " numbers.\n"				+ posCount + " of the numbers you entered where possitive.\n"				+ negCount + " of the numbers you entered where negative.\n"				+ "The sum of all the numbers is " + sum + " and the average is " + avg + ".");	}}