NLKappa

Homework 2

Sep 24th, 2017
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.04 KB | None | 0 0
  1. package com.company;
  2.  
  3.         import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7.     public static void main(String[] args) {
  8.         System.out.println("Введите цену товара (руб. и коп.): ");
  9.         Scanner sc = new Scanner(System.in);
  10.         int a = sc.nextInt();
  11.         int b = sc.nextInt();
  12.         System.out.println("Введите, сколько у вас есть денег (руб. и коп.): ");
  13.         int c = sc.nextInt();
  14.         int d = sc.nextInt();
  15.         int e = c - a;
  16.         int f = d - b;
  17.         if (e >= 0 && f >= 0) {
  18.             System.out.printf("Ваша сдача: %d руб. и %d коп. Приходите ещё.", e, f);
  19.         } else if (f <= 0 && e > 0) {
  20.             e = e - 1;
  21.             f = d - b + 100;
  22.             System.out.printf("Ваша сдача: %d руб. и %d коп. Приходите ещё.", e, f);
  23.         } else {
  24.             System.out.println("Вам не хватает денег, приходите, как накопите.");
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment