Programming/Java Algorithm 기초

    Max · Min Algoritm - 최댓값·최솟값 알고리즘

    Max Algoritm - 최댓값 알고리즘 Initialize(초기설정) 과정이 있는데, max변수에 Integer형이 가질 수 있는 최솟값을 선언함. public class MaxAlgorithm { public static void main(String[] args) { //[1] initialize int max = Integer.MIN_VALUE; //[2]input int[] values = {-6, -5, -2, -15, -56, -1, 0, 5}; int i = 0; //[3]process for(i = 0; i max) { max = values[i]; } } //[4]output System.out.println(va..

    Average Algoritm - 평균 알고리즘

    Average Algoritm - 평균 알고리즘 public class MaxAlgoritm { public static void main(String[] args) { int[] numbers = {42,56,95,35,80,79,96}; int sum = 0; int count=0; for(int i = 0; i = 80 && numbers[i]

    Count Algorithm - 개수 알고리즘

    Count Algorithm - 개수 알고리즘 n개의 정수 중 조건에 맞는 정수의 개수를 구하는 알고리즘 package countAlgorithm; //[?] n개의 정수 중 13의 배수의 개수 (건수, 횟수) /* * 개수 알고리즘(Count Algorithm): 주어진 범위에 주어진 조건에 해당하는 자료들의 개수 */ public class CountAlgorithm { public static void main(String[] args) { //[1] Input int[] numbers = {13,23,46,43,26,76,56,39,52}; int count = 0; //[2] Process for(int i = 0; i < numbers.length; i++) if (numbers[i] % 13..

    Arithmetic Sequence - 등차 수열

    Arithmetic Sequence - 등차 수열 주어진 범위에서 등차 수열을 구할 때 쓰는 알고리즘. package arithmeticSequence; //[?]: 1부터 20까지 정수 중 홀수의 합을 구하는 프로그램 /* * 등차수열(Arithmetic Sequence): 연속하는 두 수의 차이가 일정한 수열 */ public class ArithmeticSequence { public static void main(String[] args) { //[1] Input int i; int sum = 0; //[2] Process for(i = 1; i

    Sum Algorithm - 합계 알고리즘

    Sum Algoritm - 합계 알고리즘 조건에 맞는 요소의 합계를 구하는 알고리즘 for문 - if문으로 구성됨. package sumAlgoritm; //[?] n명의 국어 점수 중에서 80점 이상인 점수의 합계 /* * 합계 알고리즘 (sum algorithm) : 주어진 범위에 주어진 조건에 해당하는 자료들의 합계 */ public class SumAlgorithm { public static void main(String[] args) { //[1] Input int[] student = {50, 85, 65, 80, 75, 90, 100}; int sum = 0; //[2] Process for(int i = 0; i = ..