Skip to content

Instantly share code, notes, and snippets.

@staffordsmith83
Created August 18, 2020 09:13
Show Gist options
  • Save staffordsmith83/9a20460d476b39174b77a05a168db41c to your computer and use it in GitHub Desktop.
Save staffordsmith83/9a20460d476b39174b77a05a168db41c to your computer and use it in GitHub Desktop.
A bus tour of Europe has been very successful. Due to an increase in the number of people that want to go on a tour, the tour company decided to increase the height of the bus. The new height of the bus is exactly N centimeters. But the tour’s route runs under a lot of bridges, and there is a chance that the bus will crash into one of these brid…
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int busHeight = sc.nextInt();
int numBridges = sc.nextInt();
int bridgeHeight;
boolean crash = false;
for (int i = 0; i < numBridges; i++) {
bridgeHeight = sc.nextInt();
if (busHeight >= bridgeHeight) {
System.out.println("Will crash on bridge " + (i + 1));
crash = true;
break;
} else {
crash = false;
}
}
if (!crash) {
System.out.println("Will not crash");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment