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

03. Graduation pt.2 - Помощ!!

package Homework;

import java.util.Scanner;

public class Zad3 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);


        String name = scanner.nextLine();

        int year= 0;
        int gradeLessThan4=0;

        double sum=0;
        while (year <=12){
            double grade=Double.parseDouble(scanner.nextLine());
            if (grade>=4.00){
                sum= sum+grade;


            }
            if (grade<4.00){
                gradeLessThan4++;

                if (gradeLessThan4>1){
                    System.out.printf("%s has been excluded at %d grade",name,year);

                }

            }
            year++;
        }

        double average=sum/12;
        if (average>=4.00){
            System.out.printf("%s graduated. Average grade: %.2f",name,average);

        }
    }
}
Тагове:
TeodorStefanovPld avatar TeodorStefanovPld 1276 Точки
Best Answer
if (gradeLessThan4>1){
                    System.out.printf("%s has been excluded at %d grade",name,year);

еи тук ако влезеш в тоя иф  трябва да счупиш цикъла и да спреш приемането на данни не просто да отпечаташ че са го скъсали.

и долу проверката ти за аverage може да ти създаде проблем дори да има 2 оценки под 4, тоест 6 6 3 3 ,18/4  >4 средно.

0
ucko0o avatar ucko0o 1 Точки
import java.util.Scanner;

public class Practice {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        String name = scanner.nextLine();

        int counter = 0;
        int poor = 0;
        double sum = 0;

        while(counter < 12){
            double currentGrade = Double.parseDouble(scanner.nextLine());
            if(currentGrade >= 4.00){
                sum += currentGrade;
            }
            else{
                ++poor;
                if(poor == 2 ){
                    System.out.printf("%s has been excluded at %d grade", name, counter);
                    break;
                }
            }
            counter++;
        }
        if (counter == 12){
            sum /= 12;
            System.out.printf("%s graduated. Average grade: %.2f", name, sum);
        }

    }
}

0
YuliyanTe avatar YuliyanTe 0 Точки
import java.util.Scanner;

public class graduationTwo {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        String name = scanner.nextLine();

        int counter = 1;
        double graduates = 0;

        while (counter <=12) {
            double graduate = Double.parseDouble(scanner.nextLine());
            if (graduate >= 4) {
                graduates += graduate;
            } else {
                System.out.printf("%s has been excluded at %d grade" , name, counter);
                break;
            }
            counter++;
        }if (counter>=12){
            double average = graduates / 12;
            System.out.printf("%s graduated. Average grade: %.2f", name, average);
        }

    }
}

0