본문 바로가기

Dev82

3. 평균 알고리즘(Average Algorithm) //[?] n명의 점수 중에서 80점 이상 95점 이하인 점수의 평균 /** * 평균 알고리즘(Average Algorithm = AVG): 주어진 범위에 주어진 조건에 해당하는 자료들의 평균 */ public class AverageAlgorithm2 { public static void main(String[] args) { int[] data = { 90, 65, 78, 50, 95 }; int sum = 0; // 합계 담는 그릇 int count = 0; // 개수 담는 그릇 for (int i = 0; i = 80 && data[i] 2022. 8. 8.
2. 개수 알고리즘(Count Algorithm) //[?] n개의 정수 중 13의 배수의 개수(건수, 횟수) /** * 개수 알고리즘(Count Algorithm): 주어진 범위에 주어진 조건에 해당하는 자료들의 개수 */ public class CountAlgorithm2 { public static void main(String[] args) { int[] numbers = { 11, 12, 13, 13, 15, 13 }; int count = 0; // 개수를 저장할 변수는 0으로 초기화 for (int i = 0; i < numbers.length; i++) { if (numbers[i] % 13 == 0) { count++; } } System.out.println(numbers.length + "개의 정수 중 13의 배수의 개수: " + c.. 2022. 8. 8.
1-1. 등차수열(Arithmetic Sequence) //[?] 1부터 20까지의 정수 중 홀수의 합을 구하는 프로그램 /** * 등차수열(Arithmetic Sequence): 연속하는 두 수의 차이가 일정한 수열 */ public class ArithmeticSequence2 { public static void main(String[] args) { int sum = 0; // sum 변수 선언, 0으로 초기화 for (int i = 1; i Arithmatic Sequence // " " 2022. 8. 8.
1. 합계 알고리즘 (Sum Algorithm) //[?] n명의 국어 점수 중에서 80점 이상인 점수의 합계 /** * 합계 알고리즘: 주어진 범위에 주어진 조건에 해당하는 자료들의 합계 */ public class SumAlgorithm2 { public static void main(String[] args) { int[] scores = { 100, 75, 50, 37, 90, 95 }; int sum = 0; // 결과값 담김 for (int i = 0; i 0에서 scores.length까지) if(scores[i] >= 80) { // 만약에 scores배열의 i 번째 데이터가 80보다 크거나 같다면 sum += scores[i]; // SUM 영역 (=> sum에 누적을 시.. 2022. 8. 8.