본문 바로가기

전체 글116

5. 최솟값 알고리즘 (Min Algorithm) //[?] 주어진 데이터 중에서 가장 작은 '짝수'값 /** * 최솟값 알고리즘(Min Algorithm): (주어진 범위 + 주어진 조건)의 자료들의 가장 작은 값 */ public class MinAlgorithm2 { public static void main(String[] args) { int min = Integer.MAX_VALUE; int[] numbers = { 2, 5, 3, 7, 1 }; for (int i = 0; i < numbers.length; i++) { if (numbers[i] < min && numbers[i] % 2 == 0) { min = numbers[i]; // MIN: 더 작은 값으로 할당 } } System.out.println("짝수 최솟값: " + min).. 2022. 8. 8.
4. 최댓값 알고리즘 (Max Algorithm) //[?] 주어진 데이터 중에서 가장 큰 값 구하기 /** * 최댓값 알고리즘(Max Algorithm): (주어진 범위 + 주어진 조건)의 자료들의 가장 큰 값 */ public class MaxAlgorithm2 { public static void main(String[] args) { int max = Integer.MIN_VALUE; // Initilize 초기화 | 정수 형식의 데이터 중 가장 작은 값으로 초기화 *** int[] numbers = { -2, -5, -3, -7, -1 }; for (int i = 0; i max) { max = numbers[i]; // MAX: 더 큰 값으로 할당 } } System... 2022. 8. 8.
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.