Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class CinemaVoucher {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int voucherValue = Integer.parseInt(scanner.nextLine());
- int tickets = 0;
- int other = 0;
- int price;
- String command = scanner.nextLine();
- while (!command.equals("End")) {
- String purchase = command;
- if (purchase.length() > 8) {
- price = purchase.charAt(0) + purchase.charAt(1);
- } else {
- price = purchase.charAt(0);
- }
- if (price > voucherValue) {
- break;
- }
- if (purchase.length() > 8) {
- tickets++;
- } else {
- other++;
- }
- voucherValue = voucherValue - price;
- command = scanner.nextLine();
- }
- System.out.println(tickets);
- System.out.println(other);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement