yoni
3회차 code 본문
package oop;
public class Mean {
public void avg(int java, int jsp) {
int tot = 0;
int avg = 0;
tot = java + jsp;
avg = tot / 2;
System.out.println("1) " + avg);
}
public void avg(int java, int jsp, int spring) {
int tot = 0;
int avg = 0;
tot = java + jsp + spring;
avg = tot / 3;
System.out.println("2) " + avg);
}
public void avg(int java, int jsp, double spring) {
int tot = 0;
int avg = 0;
tot = (int)(java + jsp + spring);
avg = tot / 3;
System.out.println("3) " + avg);
}
public void avg(double java, double jsp, double spring) {
int tot = 0;
int avg = 0;
tot = (int)(java + jsp + spring);
avg = tot / 3;
System.out.println("4) " + avg);
}
public void avg(String name, int java, int jsp, int spring) {
int tot = 0;
int avg = 0;
tot = (int)(java + jsp + spring);
avg = tot / 3;
System.out.println("5) " + name + ": "+ avg);
}
public void avg(int[] datas) {
int tot = 0;
int avg = 0;
for (int i = 0; i < datas.length; i++) {
tot = tot + datas[i];
}
avg = tot / datas.length;
System.out.println("6) 요소의 갯수: " + datas.length + "/ 평균: " + avg);
}
}
--------------------------------------------------------------
package oop;
public class MeanMain {
public static void main(String[] args) {
Mean mean = new Mean();
mean.avg(90, 100);
mean.avg(90, 92, 86);
mean.avg(80, 75, 79.2);
mean.avg(65.5, 78.7, 93.5);
mean.avg("왕눈이", 80, 100, 90);
mean.avg("아로미", 80, 90, 100);
mean.avg("개구리", 60, 80, 70);
mean.avg("투투", 65, 78, 90);
mean.avg("개미", 68, 72, 85);
int[] datas = {86, 95, 65, 85, 75}; // 5
mean.avg(datas);
int[] datas2 = {86, 95, 65, 85, 75, 100}; // 6
mean.avg(datas2);
int[] datas3 = {86, 95, 65}; // 3
mean.avg(datas3);
}
}
'java of educational by contents' 카테고리의 다른 글
[14] 다양한 메소드의 리턴 실습 ★ (0) | 2018.12.01 |
---|---|
[13][OOP] 값을 리턴하는 메소드, 문자열의 리턴, 숫자의 리턴 ★ (0) | 2018.12.01 |
[11][OOP] 클래스 선언, 객체 생성, 필드(변수)의 사용, 필드(변수)의 사용 실습 (0) | 2018.12.01 |
권장 자격증 (0) | 2018.12.01 |
[10] for문의 다양한 실습 ★ (0) | 2018.12.01 |
Comments