Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class MoneyPrizeIvelin {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double parts = Double.parseDouble(scanner.nextLine());
- double moneyForOnePoint = Double.parseDouble(scanner.nextLine());
- double totalpoints = 0;
- double price = 0.0;
- double pointsEven = 0;
- double pointsOdd = 0;
- for (int i = 1; i <= parts; i++) { //Тук "i" трябва да започва от 1, иначе ти дава резултат по-малък с едно.
- double points = Double.parseDouble(scanner.nextLine());
- //totalpoints += points; - този ред го изтрих, защото нямаш нужда от него.
- if (i % 2 == 0 ) {
- pointsEven += (points * 2);
- }else {
- pointsOdd += points;
- }
- totalpoints = pointsEven + pointsOdd; //Това ти беше извън цикъла и не смяташе правилно.
- }
- price = moneyForOnePoint * totalpoints;
- System.out.printf("The project prize was %.2f lv.",price);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement