星期一, 10月 24, 2005

project2_7


import javax.swing.JOptionPane;
public class project2_7
{
public static void main(String[] args)
{
String thePrice=JOptionPane.showInputDialog("Enter price of item\n"+"(from 25 cents to a dollar, in 5-cent increments):");
int price=Integer.parseInt(thePrice);
System.out.println("You bought an item for "+price+" cents and gave me a dollar,\n"+"so your change is");
int change = 100 - price;
int quarter=0,dime=0,nickel=0;
if(change >= 25)
{
quarter = change / 25;
change = change%25;
}
if(change>=10 &&amp; change <25) dime =" change/10;" change =" change%10;">=5 && change <10)
{
nickel = change/5;
change = change%5;
}
if(change<0)
{
System.out.println("You should pay more money!!!");
}
System.out.println(quarter+" quarters,");
System.out.println(dime+" dimes,and");
System.out.println(nickel+" nickels.");
System.exit(0);
}
}

0 Comments:

張貼留言

<< Home