Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class ExerciseFourV3 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String command = scanner.nextLine();
- int startingDistance = 5364;
- int days = 1;
- int metersClimbed = 0;
- while (!command.equalsIgnoreCase("end")) {
- if (command.equalsIgnoreCase("Yes")){
- metersClimbed = Integer.parseInt(scanner.nextLine());
- days++;
- } else if (command.equalsIgnoreCase("No")){
- metersClimbed = Integer.parseInt(scanner.nextLine());
- }
- startingDistance += metersClimbed;
- if (startingDistance >= 8848) {
- System.out.printf("Goal reached for %d days!" , days);
- break;
- }
- if (days == 5) {
- System.out.printf("Failed!%n%d" ,startingDistance);
- break;
- }
- command = scanner.nextLine();
- if (command.equalsIgnoreCase("End")) {
- System.out.printf("Failed!%n%d" , startingDistance);
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement