# Thread: just wana see what u think

1. Member
Join Date
Feb 2011
Posts
2
Rep Power
0

## just wana see what u think

Hi im new to this forum!
Im taking intro to java.
one of my assignments is to figure out how many quarters,nickles,dimes,pennies i am supposed to return for change.
i got it working just wana get input on improvements or other ways that this should be done.

Java Code:
```import java.util.Scanner;
import java.util.*;
public class J3 {

public static void main(String[] args)
{
while(true){
float change3,total,bill=0;

int change,change2,quarter,dime,nickel,pennie,doller;

Scanner input = new Scanner(System.in);

System.out.println("What is the total amount?\n");
total=input.nextFloat();

while (bill<total){
bill=input.nextFloat();
}
change3=bill-total;

bill*=100;
total*=100;
int bill2 = (int) bill;
int total2 = (int) total;

change2=bill2-total2;
change=change2;

doller=change/100;
change=change%100;
quarter=change/25;
change=change%25;
dime=change/10;
change=change%10;
nickel=change/5;
change=change%5;
pennie=change/1;
System.out.printf("%d doller(s)\n",doller);
System.out.printf("%d quarter(s)\n",quarter);
System.out.printf("%d dime(s)\n",dime);
System.out.printf("%d nickel(s)\n",nickel);
System.out.printf("%d pennie(s)\n",pennie);
}
}
}```

2. Place the nominal amounts in an array and use a loop.
Use if statement to only print amounts greater than 0 ie do not display "0 dimes"
Use if statement to add s only when amount is greater than 1 ie "1 quarter 2 dimes". Penny/Pennies hmmmm!

3. Member
Join Date
Feb 2011
Posts
2
Rep Power
0
thank you very much havent covered arrays yet.
looks like i got some reading to do thank you. i will post revised code :)

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•