SHARE
TWEET

Untitled

a guest Apr 20th, 2019 37 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package examReal;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class cinemaVoucher {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         int voucher = Integer.parseInt(scanner.nextLine());
  9.         String command = scanner.nextLine();
  10.         double price = 0.0;
  11.         int tickets = 0;
  12.         int others = 0;
  13.  
  14.  
  15.         while (!command.equalsIgnoreCase("End")) {
  16.             String name = command;
  17.             int letter1 = name.charAt(0);
  18.             int letter2 = name.charAt(1);
  19.             int lenght = name.length();
  20.  
  21.             if (lenght > 8) {
  22.                 price = letter1 + letter2;
  23.             } else if (lenght <= 8) {
  24.                 price = letter1;
  25.             }
  26.             if (voucher - price >= 0) {
  27.                 voucher -= price;
  28.                 if (lenght>8){
  29.                     tickets++;
  30.                 }else if (lenght<=8){
  31.                     others++;
  32.                 }
  33.             } else
  34.                 break;
  35.  
  36.             command = scanner.nextLine();
  37.             }
  38.  
  39.  
  40.  
  41.             System.out.printf("%d %n%d", tickets, others);
  42.  
  43.         }
  44.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top