Софтуерно Инженерство
Loading...
+ Нов въпрос
s.borisov avatar s.borisov 0 Точки

8. Завършване - част 2

Колеги, моля за помощ за задача 8. Нещо не мога да хвана къде бъркам.

import java.util.Scanner;

public class GraduationPartTwo {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String studentName = scanner.nextLine();
        double sum = 0;
        int count = 0;
        boolean end = false;
        while (count < 12) {
            double grade = Double.parseDouble(scanner.nextLine());
            if (grade > 4) {
                sum = sum + grade;
                count++;
                end = true;
            } else {
                grade = Double.parseDouble(scanner.nextLine());
                count++;
                break;
            }
        }
        if (end) {
            System.out.printf("%s graduated. Average grade: %.2f", studentName, sum / 12);
        } else {
            System.out.printf("%s has been excluded at %d grade", studentName, count);
        }
    }
}
Тагове:
0
Programming Basics with Java
skenderskiantonio avatar skenderskiantonio 19 Точки

 Поправих кода ти, но те съветвам да промениш имената на променливите си. Ето кода: https://pastebin.com/VdPbrPBi

0
s.borisov avatar s.borisov 0 Точки

Много благодаря!

0
IvailoNetzov avatar IvailoNetzov 1 Точки

eto ti i edno reshenie bez boolean ako se burkash 

//////////////////////////////////////////////////////////

 

import java.sql.SQLOutput;
import java.util.Scanner;

public class Vacation {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
  String name =scanner.nextLine();
    
       int counter = 0 ;
        int counterForExpeled = 0;
        double avrGrade =0.0;


                while(counter<12){
                    double grade = Double.parseDouble(scanner.nextLine());
                    if (grade<4.00){
                        int expeled = 0;
                        expeled++;
                        counterForExpeled+=expeled;
                        if (counterForExpeled>1){
                            System.out.printf("%s has been excluded at %d grade",name,counter+1);
                            break;

                        }
                    }else if(grade>=4.00) {
                       // grade = Double.parseDouble(scanner.nextLine());
                        avrGrade += grade;


                        counter++;

                    }
                }
                if (counter==12) {
                    System.out.printf("%s graduated. Average grade: %.2f", name, (avrGrade / 12));
                }
    }
}

0
12/10/2019 23:20:01