import java.util.*;
class student {
int max=0;
int[] arr=new int[5];
String name;
int kor, math, eng;
student() {
}
student(String name, int kor, int math, int eng) {
this.name=name;
this.kor=kor;
this.math=math;
this.eng=eng;
}
void mean() {
int mean=(kor+math+eng)/3;
System.out.println(name+"의 "+"평균은 " + mean);
}
}
public class Main {
public static void main(String[] args) {
String honour;
int max=0;
Scanner t = new Scanner(System.in);
// 클래스의 배열 선언: 주소값 할당만을 위한 준비
student []x = new student[5];
for(int i=0; i<x.length; i++) {
x[i] = new student();
x[i].name = t.next();
x[i].kor = t.nextInt();
x[i].math = t.nextInt();
x[i].eng = t.nextInt();
x[i].mean();
}
for(int i=0;i<x.length;i++) {
if(mean>max) {
max=mean;
honour = x[i].name;
}
System.out.println(honour);
}
}
}
top of page

기능을 테스트하려면 라이브 사이트로 이동하세요.
8월22일
8월22일
댓글 1개
좋아요
댓글(1)
bottom of page
import java.util.*; class student { int max=0; int[] arr=new int[5]; String name; int kor, math, eng; student() { } student(String name, int kor, int math, int eng) { this.name=name; this.kor=kor; this.math=math; this.eng=eng; } int mean() { int mean=(kor+math+eng)/3; System.out.println(name+"의 "+"평균은 " + mean); return mean; } } public class Main { public static void main(String[] args) { String honour; int max=0; Scanner t = new Scanner(System.in); // 클래스의 배열 선언: 주소값 할당만을 위한 준비 student []x = new student[5]; for(int i=0; i<x.length; i++) { x[i] = new student(); x[i].name = t.next(); x[i].kor = t.nextInt(); x[i].math = t.nextInt(); x[i].eng = t.nextInt(); x[i].mean(); } for (int i = 0; i < x.length; i++) { if (x[i].mean() > max) { max = x[i].mean(); } honour = x[i].name; } } }