Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package S5_WhileLoops;
- import java.util.Scanner;
- public class Coins {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double change = Double.parseDouble(scanner.nextLine());
- // convert change only in stotinki
- double changeInSt = change * 100;
- // save count of coins
- int stotinkiCount = 0;
- // iterate until we return the change
- while (changeInSt > 0) {
- // return 2 lv = 200 st.
- if(changeInSt >= 200) {
- changeInSt = changeInSt - 200;
- }
- // return 1 lv = 100 st.
- else if(changeInSt >= 100) {
- changeInSt = changeInSt - 100;
- }
- // return 50 st.
- else if(changeInSt >= 50) {
- changeInSt = changeInSt - 50;
- }
- // return 20 st.
- else if(changeInSt >= 20) {
- changeInSt = changeInSt - 20;
- }
- // return 10 st.
- else if(changeInSt >= 10) {
- changeInSt = changeInSt - 10;
- }
- // return 5 st.
- else if(changeInSt >= 5) {
- changeInSt = changeInSt - 5;
- }
- // return 2 st.
- else if(changeInSt >= 2) {
- changeInSt = changeInSt - 2;
- }
- // return 1 st.
- else if(changeInSt >= 1) {
- changeInSt = changeInSt - 1;
- }
- // for stotinki < 0 (floating number error)
- else {
- break;
- }
- stotinkiCount++;
- }
- System.out.println(stotinkiCount);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement