PROJECT2.07
PROJECT2.07
import javax.swing.JOptionPane;
public class q3
{
public static void main(String[] args)
{
String mycount=JOptionPane.showInputDialog("Enter the price of item (between 25 cents and a dollar): ");
int itemPrice = Integer.parseInt(mycount);
int quarter=(100-itemPrice)/25;
int change=(100-itemPrice)-quarter*25;
int dime,nickel;
dime=change/10;
nickel=(change-dime*10)/5;
JOptionPane.showMessageDialog(null,"You bought an item for "+itemPrice+" cents and gave me a dollar.So your change is");
JOptionPane.showMessageDialog(null,+quarter+" quarters. "+dime+" dimes. "+nickel+" nickels. ");
System.exit(0);
}
}
程式結果連結
import javax.swing.JOptionPane;
public class q3
{
public static void main(String[] args)
{
String mycount=JOptionPane.showInputDialog("Enter the price of item (between 25 cents and a dollar): ");
int itemPrice = Integer.parseInt(mycount);
int quarter=(100-itemPrice)/25;
int change=(100-itemPrice)-quarter*25;
int dime,nickel;
dime=change/10;
nickel=(change-dime*10)/5;
JOptionPane.showMessageDialog(null,"You bought an item for "+itemPrice+" cents and gave me a dollar.So your change is");
JOptionPane.showMessageDialog(null,+quarter+" quarters. "+dime+" dimes. "+nickel+" nickels. ");
System.exit(0);
}
}
0 Comments:
張貼留言
<< Home