package nameyu;import java.util.Scanner;public class Test { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); System.out.print("Enter an amount in double,for example 11.56:"); double amount=input.nextDouble(); int remainingAmount=(int)(amount*100); int numberOfOneDollars=remainingAmount/100; remainingAmount=remainingAmount%100; int numberOfQuarters=remainingAmount/25; remainingAmount=remainingAmount%25; int numberOfDimes=remainingAmount/10; remainingAmount=remainingAmount%10; int numberOfNickels=remainingAmount/5; remainingAmount=remainingAmount%5; int numberOfPennies=remainingAmount; String output="Your amount"+amount+"consists of\n"; if (numberOfOneDollars>1){ output+="\t"+numberOfOneDollars+"dollars\n"; }else if(numberOfOneDollars==1){ output+="\t"+numberOfOneDollars+"dollar\n"; }else output=output; if (numberOfQuarters>1){ output+="\t"+numberOfQuarters+"quarters\n"; }else if(numberOfQuarters==1){ output+="\t"+numberOfQuarters+"quarter\n"; }else output=output; if (numberOfDimes>1){ output+="\t"+numberOfDimes+"dimes\n"; }else if(numberOfDimes==1){ output+="\t"+numberOfDimes+"dime\n"; }else output=output; if (numberOfNickels>1){ output+="\t"+numberOfNickels+"nickels\n"; }else if(numberOfNickels==1){ output+="\t"+numberOfNickels+"nickel\n"; }else output=output; if (numberOfPennies>1){ output+="\t"+numberOfPennies+"pennies\n"; }else if(numberOfPennies==1){ output+="\t"+numberOfPennies+"pennie\n"; }else output=output; System.out.println(output); } }
|