알고리즘이란?

songB·2022년 3월 17일
0

알고리즘

목록 보기
1/1

알고리즘(Algorithm)

어떠한 문제를 해결하기 위해 정해진, 명확하게 정의되고 순서가 있는 유한 개의 규칙으로 이루어진 집합.

말이 어려우니, 문제풀이 과정이라고 이해해야겠다.

예시 코드

public class Max3 {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		System.out.println("세 정수의 최댓값을 구합니다.");
		System.out.print("a의 값: ");
		int a = stdIn.nextInt();
		System.out.print("b의 값: ");
		int b = stdIn.nextInt();
		System.out.print("c의 값: ");
		int c = stdIn.nextInt();
		
		int max = a;
		if (b > max) max = b;
		if (c > max) max = c;
		
		System.out.println("최댓값은 "+max+" 입니다.");
	}
}

위 코드는 세 정수의 최댓값을 구하는 프로그램이다.
알고리즘 순서도(flowchart)는 아래와 같다.

profile
백송은입니다.

0개의 댓글