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.
答案 0 :(得分: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();
答案 1 :(得分: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");
}
}
答案 2 :(得分: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");
}
}