2005-10-31

lab product of n positive numbers

package loop;
import javax.swing.JOptionPane;
public class loop
{
public static void main(String[] args)
{
String enter=JOptionPane.showInputDialog("Please enter a nonnegative number.\n (If you enter a negative number, it exits)");
int x = Integer.parseInt(enter);
int s=1;
while(x >= 0)
{
s=s*x;
enter=JOptionPane.showInputDialog("Please enter a nonnegative number.\n (If you enter a negative number, it exits)");

x = Integer.parseInt(enter);
}
System.out.println("the answer of producting is "+ s);

System.exit(0);
}
}

0 Comments:

張貼留言

<< Home