2005-10-24

Project 7

/*視窗化*/

package homework4_2;
import javax.swing.JOptionPane;
public class homework4_2
{
public static void main (String[] args)
{
while(1==1)
//好像不能用while(1)

{
String price=JOptionPane.showInputDialog("Please enter the price of an item which you want to buy.");
int p = Integer.parseInt(price);
String answer=JOptionPane.showInputDialog("It is " + p + " cents. Sure?(y=1/n=0)");
//可再次確認輸入是否正確,如不正確可以重新輸入
int ans = Integer.parseInt(answer);
if (ans == 1)
{
int a=100-p;
int q=a/25;
int b=a%25;
int d=b/10;
int c=b%10;
int n=c/5;
System.out.println("You bought an item for "+p+" cents and give me a dollar, so your change is\n"+q+" quartes,\n"+d+" dimes, and\n"+n+" nickels.");
break;
}
}
}
}



0 Comments:

張貼留言

<< Home