Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Calculate_Change {
- public static void main(String[] args) {
- Scanner sc=new Scanner(System.in);
- double bill=sc.nextDouble();
- double pay=sc.nextDouble();
- int counterLev=0;
- int counterFifty=0;
- int counterTwenty=0;
- int counterTen=0;
- int counterFive=0;
- int counterTwo=0;
- int counterOne=0;
- double change=(pay-bill)*100;
- while(change>0){
- if(change>=100)
- {
- change-=100;
- counterLev++;
- }
- else if(change>=50){
- change-=50;
- counterFifty++;
- }
- else if (change>=20){
- change-=20;
- counterTwenty++;
- }
- else if(change>=10)
- {
- change-=10;
- counterTen++;
- }
- else if(change>=5)
- {
- change-=5;
- counterFive++;
- }
- else if(change>=2)
- {
- change-=2;
- counterTwo++;
- }
- else if(change>=1){
- change-=1;
- counterOne++;
- }
- }
- if(counterLev>1){
- System.out.printf("%d x 1 lev %n",counterLev);
- }
- if(counterFifty>0){
- System.out.printf("%d x 50 stotinki %n",counterFifty);
- }
- if(counterTwenty>0){
- System.out.printf("%d x 20 stotinki %n",counterTwenty);
- }
- if(counterTen>0){
- System.out.printf("%d x 10 stotinki %n",counterTen);
- }
- if(counterFive>0){
- System.out.printf("%d x 5 stotinki %n",counterFive);
- }
- if(counterTwo>0){
- System.out.printf("%d x 2 stotinki %n",counterTwo);
- }
- if(counterOne>1){
- System.out.printf("%d x 1 stotinki %n",counterOne);
- }
- else if(counterOne==1){
- System.out.printf("%d x 1 stotinka",counterOne);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment