0
import java.util.Scanner;



public class Minimumchange {

  public static void main(String[] args) 
  {         
    System.out.println("please enter the number of change 1-99");
    System.out.println("enter 0 to exit the program");
    Scanner Userinput = new Scanner(System.in);
    int cntrquart = 0;
    int cntrdimes = 0;
    int cntrpennies = 0;
    int cntrnickels = 0;

    //quarters
    int chaaching = Userinput.nextInt();



    int quarters = chaaching;

    while (quarters >= 25)
    {
       quarters = quarters  - 25;
       cntrquart = cntrquart + 1;
    }


    //dimes 
    int dimes = quarters;


    while (dimes >= 10)
    {
       dimes = dimes  - 10;
       cntrdimes = cntrdimes + 1;
    }



    //nickels 
    int nickels = dimes;


    while (nickels >= 5)
    {
       nickels = nickels  - 5;
       cntrnickels = cntrnickels + 1;
    }



    //pennies
    int pennies = nickels;


    while (pennies >= 1)
    {
       pennies = pennies  - 1;
       cntrpennies = cntrpennies + 1;
    }



    //outputs
    System.out.println("mumber of quarters:" + cntrquart);
    System.out.println("number of dimes:" + cntrdimes);
    System.out.println("number of nickels:" + cntrnickels);
    System.out.println("numberof pennies:" + cntrpennies);


    System.out.println("Thank you for using Dark Alley Development");
   }

}

用户输入 1-99,我的程序会告诉您制作 x 所需的硬币、硬币、镍币和便士的最小数量。我希望程序一遍又一遍地运行,直到用户输入 0。

4

3 回答 3

0
import java.util.Scanner;

public class Minimumchange {

public static void main(String[] args) 
{
int chaaching = 1;
do {

System.out.println("please enter the number of change 1-99");
System.out.println("enter 0 to exit the program");
Scanner Userinput = new Scanner(System.in);
int cntrquart = 0;
int cntrdimes = 0;
int cntrpennies = 0;
int cntrnickels = 0;

//quarters
chaaching = Userinput.nextInt();


int quarters = chaaching;

while (quarters >= 25)
{
   quarters = quarters  - 25;
   cntrquart = cntrquart + 1;
}


//dimes 
int dimes = quarters;


while (dimes >= 10)
{
   dimes = dimes  - 10;
   cntrdimes = cntrdimes + 1;
}



//nickels 
int nickels = dimes;


while (nickels >= 5)
{
   nickels = nickels  - 5;
   cntrnickels = cntrnickels + 1;
}



//pennies
int pennies = nickels;


while (pennies >= 1)
{
   pennies = pennies  - 1;
   cntrpennies = cntrpennies + 1;
}


//outputs
System.out.println("mumber of quarters:" + cntrquart);
System.out.println("number of dimes:" + cntrdimes);
System.out.println("number of nickels:" + cntrnickels);
System.out.println("numberof pennies:" + cntrpennies);

} while (chaaching !=0);


System.out.println("Thank you for using Dark Alley Development");
}

}
于 2013-11-06T02:39:26.697 回答
0
import java.util.Scanner;

public class Minimumchange {

  public static void main(String[] args) 
  {
    while(true) {         
      System.out.println("please enter the number of change 1-99");
      System.out.println("enter 0 to exit the program");
      Scanner Userinput = new Scanner(System.in);
      int cntrquart = 0;
      int cntrdimes = 0;
      int cntrpennies = 0;
      int cntrnickels = 0;

      //quarters
      int chaaching = Userinput.nextInt();
      if(chaaching == 0) {
        break;
      }


      int quarters = chaaching;

      while (quarters >= 25)
      {
        quarters = quarters  - 25;
        cntrquart = cntrquart + 1;
      }


      //dimes 
      int dimes = quarters;


      while (dimes >= 10)
      {
        dimes = dimes  - 10;
        cntrdimes = cntrdimes + 1;
      }



      //nickels 
      int nickels = dimes;


      while (nickels >= 5)
      {
        nickels = nickels  - 5;
        cntrnickels = cntrnickels + 1;
      }



      //pennies
      int pennies = nickels;


      while (pennies >= 1)
      {
        pennies = pennies  - 1;
        cntrpennies = cntrpennies + 1;
      }



      //outputs
      System.out.println("mumber of quarters:" + cntrquart);
      System.out.println("number of dimes:" + cntrdimes);
      System.out.println("number of nickels:" + cntrnickels);
      System.out.println("number of pennies:" + cntrpennies);

    }

    System.out.println("Thank you for using Dark Alley Development");
  }
}
于 2013-11-06T02:35:45.050 回答
0
while (input != '0') {
   // your code here
} 
System.err.println("Now exiting as zero entered"); // telling how it works, in case you aren't aware
System.exit();
于 2013-11-06T02:33:43.357 回答