Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class SuitcaseLoad2 {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- double volRemain = Double.parseDouble(scan.nextLine());
- String volumeSuitcase;
- double counter = 0;
- boolean checkForBreak = false;
- while (true) {
- //double volSuitcase = 0.00;
- // if (volumeSuitcase.isEmpty()) break;
- volumeSuitcase = scan.nextLine();
- if ("End".equals(volumeSuitcase)) {
- break;
- }
- double volSuitcase = Double.parseDouble(volumeSuitcase);
- if (counter % 2 == 0 && counter !=0) {
- volSuitcase = volSuitcase * 1.10;
- }
- if (volRemain < volSuitcase) {
- checkForBreak = true;
- break;
- } else if (volRemain == volSuitcase ) {
- if (volRemain != 0 && (counter + 1)% 3 != 0) {
- counter++;
- }
- checkForBreak = true;
- break;
- }
- volRemain = volRemain - volSuitcase;
- counter++;
- }
- if (checkForBreak) {
- System.out.println("No more space!");
- } else {
- System.out.println("Congratulations! All suitcases are loaded!");
- }
- System.out.printf("Statistic: %.0f suitcases loaded.", counter);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement