Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package gabriela_burlakova;
- import java.util.Scanner;
- /**
- *
- * @author Gaby
- */
- public class Gabriela_Burlakova {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int numStudents;
- do {
- System.out.println("Въведи брой студенти!");
- numStudents = sc.nextInt();
- if (numStudents > 30){
- System.out.println("Въведеният брой студенти е по-голям от допустимия.");
- }
- }while (numStudents > 30);
- double gSum = 0;
- // General Sum - Сумата се използва за изчисляване средния успеха на всички студенти
- double gAvr = 0;
- // General Average - Среден успех за всички студенти
- int numMarks = numStudents * 5;
- // Общ брой оценки
- double sAvr = 0;
- // Среден успех за отделния студент
- double avrMax = 0;
- // Съхранява най-високия среден успех
- int maxIndex = 0;
- // Номерът на студента с най-висок среден успех
- double avrMin = 6;
- // Съхранява най-ниския среден успех
- int minIndex = 0;
- // Номерът на студента с най-висок среден успех
- int aboveC = 0;
- // Брой студенти със среден успех, по-висок от средния
- int belowC = 0;
- // Брой студенти със среден успех, по-нисък от средния
- double arrayStudents[][] = new double[numStudents][5];
- for (int i = 0; i < numStudents; i++) {
- for (int j = 0; j < 5; j++) {
- do{
- System.out.println("Въведи оценка №" + (j + 1) + " за студент №" + (i + 1));
- arrayStudents[i][j] = sc.nextDouble();
- if(arrayStudents[i][j] < 2 || arrayStudents[i][j] > 6){
- System.out.println("Въведените оценки трябва да са между 2 и 6");
- }
- }while (arrayStudents[i][j] < 2 || arrayStudents[i][j] > 6);
- gSum = gSum + arrayStudents[i][j];
- }
- }
- gAvr = (double) gSum / numMarks;
- for (int i = 0; i < numStudents; i++) {
- double sSum = 0;
- sAvr = 0;
- for (int j = 0; j < 5; j++) {
- sSum = sSum + arrayStudents[i][j];
- }
- sAvr = (double) sSum / 5;
- if (sAvr > avrMax) {
- avrMax = sAvr;
- maxIndex = (i + 1);
- }
- if (sAvr < avrMin) {
- avrMin = sAvr;
- minIndex = (i + 1);
- }
- if (sAvr > gAvr) {
- aboveC++;
- } else {
- belowC++;
- }
- }
- System.out.println("Средният успех на студентите през 5 семестър е " + gAvr);
- System.out.println();
- System.out.println("Номерът на студента с най-висок среден успех е " + maxIndex + "\nсъс среден успех " + avrMax);
- System.out.println();
- System.out.println("Номерът на студента с най-нисък среден успех е " + minIndex + "\nсъс среден успех " + avrMin);
- System.out.println();
- System.out.println("Броят на студентите, които имат среден успех,\nнад средния е " + aboveC);
- System.out.println();
- System.out.println("Броят на студентите, които имат среден успех,\nпод средния е " + belowC);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement