# Thread: How do you do in an input and then get an output?

1. Member Join Date
Jan 2011
Posts
40
Rep Power
0

## How do you do in an input and then get an output?

How do you make it so it ask you how much money you have used, and the amount of money you have left and it subtracts it and tells you how much you have left in bills?

Lets say you used \$20.26 , and you originally had 40 dollars you put 20.26 as the amount you spent and then you put 40 as the original amount and it outputs it as the answer as 19.74 dollars and then it breaks it down further and tells you you have 19 dollars 2 quarters 2 dimes and 4 pennies?

I'm have a hard time figuring out how to code that  Reply With Quote

2. ## Re: How do you do in an input and then get an output?  Reply With Quote

3. Member Join Date
Jan 2011
Posts
40
Rep Power
0

## Re: How do you do in an input and then get an output?

I've done this
public class s {
public static void main(String[] args)
{
int a ;
int b ;
int sub;
@SuppressWarnings("resource")
Scanner input = new Scanner(System.in);
a=input.nextInt(); // store the input a.
b=input.nextInt(); // store the input in b.

sub = a - b; //subtract the 2 two numbers

System.out.println("Your change is : " + sub); // display the result of the two numbers

}
}
And when I enter normal numbers its fine, but when i enter decimals like 10.5 i get an error and idk how it can break up the answers in dollars, quartiers, dimes and pennies.  Reply With Quote

#### Posting Permissions

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