Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class ExperienceGaining {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double neededExp = Double.parseDouble(scanner.nextLine());
- int battleCount = Integer.parseInt(scanner.nextLine());
- double currentExp = 0;
- boolean isDone = false;
- int counter = 0;
- for (int i = 1; i <= battleCount; i++) {
- double experience = Double.parseDouble(scanner.nextLine());
- counter++;
- if (i % 3 == 0) {
- currentExp += experience * 1.15;
- } else if (i % 5 == 0) {
- currentExp += experience * 0.9;
- } else {
- currentExp += experience;
- }
- if (currentExp >= neededExp) {
- isDone = true;
- break;
- }
- }
- if (isDone) {
- System.out.println(String.format("Player successfully collected his needed experience for %d battles."
- , counter));
- } else {
- System.out.println(String.format("Player was not able to collect the needed experience, %.2f more needed."
- , neededExp - currentExp));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement