자바과정/Java
Java 실습(성적처리프로그램) - 3일차
Parkej
2021. 2. 1. 10:52
/*
* 성적처리프로그램
* 입력 : 이름, 국, 영, 수
* 연산 : 총점, 평균
* 출력 : 이름, 국, 영, 수, 총, 평
*/
import java.util.Scanner;
public class arrayExam01 {
public static void main(String[] args) {
// 선언
String name;
int []score = new int[4];//국 영 수 총
float avg;
// int tot = 0;
Scanner sc = new Scanner(System.in); // 객체선언
// 입력, 연산
System.out.print("이름 입력 : ");
name = sc.next();
System.out.print("성적 입력(국 영 수) : ");
for(int i=0;i<score.length-1;i++) {
score[i] = sc.nextInt();
// tot += score[i];
score[3] += score[i];
}
// 출력
// avg = tot/(score.length-1);
avg = score[3]/3.0f; // 3.0은 더블 3.f는 float > 자동형변환
System.out.println(name);
for(int i=0;i<score.length;i++) {
System.out.println(score[i]);
}
// System.out.println(tot);
System.out.println(avg);
}
}
반응형