Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ForLoop;
- import java.util.Scanner;
- public class FanShop {
- public static void main(String[] args) {
- Scanner s = new Scanner(System.in);
- int buget = Integer.parseInt(s.nextLine());
- int n = Integer.parseInt(s.nextLine());
- int item = 0;
- int price = 0;
- for (int i = 1; i<= n; i++){
- String art = s.nextLine();
- if(art.equals("flag")){
- price += 15;
- }
- if(art.equals("hoodie")){
- price += 30;
- }
- if(art.equals("keychain")){
- price += 4;
- }
- if(art.equals("T-shirt")){
- price += 20;
- }
- if(art.equals("sticker")){
- price += 1;
- }
- item++;
- }
- if(price <= buget){
- System.out.printf("You bought %d items and left with %d lv.",item, buget - price);
- }else {
- System.out.printf("Not enough money, you need %d more lv.", Math.abs(price - buget));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement