Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Exam_darts {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int points = Integer.parseInt(scanner.nextLine());
- int moves = 0;
- String input = scanner.nextLine();
- boolean winZero = false;
- boolean loss = false;
- while (!"bullseye".equals(input)) {
- int currentPoints = Integer.parseInt(scanner.nextLine());
- moves++;
- if ("number section".equals(input)) {
- points -= currentPoints;
- } else if ("double ring".equals(input)) {
- points -= currentPoints * 2;
- } else if ("triple ring".equals(input)) {
- points -= currentPoints * 3;
- }
- if (points == 0) {
- winZero = true;
- break;
- }
- else if (points < 0){
- loss = true;
- break;
- }
- input = scanner.nextLine();
- }
- if (winZero) {
- System.out.printf("Congratulations! You won the game in %d moves!", moves);
- }
- else if (loss) {
- System.out.printf("Sorry, you lost. Score difference: %d.", Math.abs(points));
- }
- else {
- System.out.printf("Congratulations! You won the game with a bullseye in %d moves!", moves +1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement