2.11.2: Compute change. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 2

2.11.2: Compute change.

A cashier distributes change using the maximum number of five dollar bills, followed by one dollar bills. For example, 19 yields 3 fives and 4 ones. Write a single statement that assigns the number of one dollar bills to variable numOnes, given amountToChange. Hint: Use the % operator.

31st May 2020, 4:14 PM
Sandra M.
Sandra M. - avatar
3 Answers
31st May 2020, 4:24 PM
Katherine
Katherine - avatar
0
import java.util.Scanner; public class ComputingChange { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); int amountToChange; int numFives; int numOnes; amountToChange = scnr.nextInt(); numFives = amountToChange / 5; /*Your solution goes here */ System.out.print("numFives: "); System.out.println(numFives); System.out.print("numOnes: "); System.out.println(numOnes); } }
31st May 2020, 5:02 PM
Sandra M.
Sandra M. - avatar
0
Sandra M. Hi, if you want to post a coding problem- be it a challenge for others, or assistance, you might want to post them here: https://www.sololearn.com/Discuss/1270852/?ref=app This thread is a collection of coding problems from our users, feel free to check it out. Don’t forget to star the thread so you can receive updates whenever there’s a new post!
31st May 2020, 7:55 PM
Bobby Fischer
Bobby Fischer - avatar