bread, coffee and coding
[Java] 성적을 배열에 넣고 총합과 평균을 출력해 봅시다 본문
성적은 score 정수형 배열
점수는 영어, 국어, 수학
정수형배열 score를 선언하고
배열에 영어, 국어, 수학 순으로 점수를 입력해 주세요. (100, 80, 100)
Scanner 클래스 사용하여 입력해 주세요.
총점과 평균점수를 출력해 주세요.
------------------------------------------
총점 : 280
평균 : 90

(coding)
더보기
package org.example;
import java.util.Scanner;
public class TestQuiz {
public static void main(String[] args) {
int sum = 0;
int avg = 0;
int[] arr = new int[3];
int size = arr.length;
Scanner sc = new Scanner(System.in);
for(int i =0; i<size; i++) {
System.out.println("성적을 입력하세요");
arr[i] = sc.nextInt();
sum += arr[i];
}
avg = sum / arr.length;
System.out.println("총점: " + sum);
System.out.println("평균: " + avg);
}
}
동기의 인상적인 코딩

(coding)
더보기
package org.example;
import java.util.Scanner;
public class TestQuiz {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in) ;
int[] score={sc.nextInt(),sc.nextInt(),sc.nextInt()};
int sum=0;
for (int i:score) {
sum+=i;
}
System.out.println("총점: "+sum);
System.out.println("평균: "+(int)sum/score.length);
}
}
'Coding test' 카테고리의 다른 글
| Design patterns quiz (0) | 2021.07.14 |
|---|---|
| FileInputStream과 FileOutputStream(Java) (0) | 2021.07.07 |
| 프로그래머스 1단계 짝수와 홀수(C#) (0) | 2021.07.05 |
| 프로그래머스 1단계 평균 구하기(C#) (0) | 2021.07.05 |
| 프로그래머스 1단계 직사각형 별찍기(C#) (0) | 2021.07.05 |