Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- localstorage
- MySQL
- java기초
- JOIN
- JavaScript#조건문#conditional
- JavaScript
- 웹개발종합반
- sanitize-html
- javascropt
- 프로그래머스
- 스택큐
- Login
- getMinutes
- function
- 자바스크립트
- SQL
- LEFTJOIN
- 시간보여주기
- classList
- padStart
- gethours
- node.js
- 스파르타코딩클럽
- Database
- appendChild
- padEnd
- dateobject
- classname
- 백준3052번
- 올바른괄호
Archives
- Today
- Total
just do it
유클리드호제법, 재귀함수, 최대공약수 출력하기(java) 본문
유클리드호제법, 재귀함수 이용 최대공약수 출력하기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
import java.util.Scanner;
public class recursion {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Please enter an x : ");
int x = sc.nextInt();
System.out.println("Please enter an y : ");
int y = sc.nextInt();
int answer= gcd(x,y);
System.out.print("the answer is : "+ answer);
}
//유클리드호제법 & 재귀
static int gcd(int x, int y) {
if(y==0) {
return x;
}
else return gcd(y, x%y);
}
}
|
cs |
'자료구조&알고리즘 > 코딩테스트' 카테고리의 다른 글
코드업 100제(JavaScript) (0) | 2022.12.25 |
---|---|
숫자 문자열과 영단어(replace, 형변환, 프로그래머스 in java) (0) | 2022.12.14 |
백준2750번/버블정렬/java (0) | 2022.10.14 |
백준 3052번/나머지/java (0) | 2022.10.12 |
기본 알고리즘 (1) | 2022.10.07 |