Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class demo {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int startPoints = Integer.parseInt(scanner.nextLine());
- //1. startPoints == 0 -> продължава: startPoints > 0
- //2. ако уцели мишената -> ok
- //3. точки< 0
- int count = 0;
- while (startPoints > 0) {
- //играе -> хвърля
- String sector = scanner.nextLine();
- count++; //броя на ходовете
- if ("bullseye".equals(sector)) {
- System.out.printf("Congratulations! You won the game with a bullseye in %d moves!", count);
- break;
- }
- int points = Integer.parseInt(scanner.nextLine());
- //"number section", "double ring","triple ring", "bullseye"
- if ("number section".equals(sector)) {
- startPoints -= points;
- } else if ("double ring".equals(sector)) {
- startPoints -= points * 2;
- } else if ("triple ring".equals(sector)) {
- startPoints -= points * 3;
- }
- if (startPoints < 0) {
- System.out.printf("Sorry, you lost. Score difference: %d.", Math.abs(startPoints));
- break;
- } else if (startPoints == 0){
- System.out.printf("Congratulations! You won the game in %d moves!", count);
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement