알고리즘 기초 - 31 ( 팩토리얼, 함수 )
Algorithm/풀었던문제 2019. 12. 30. 13:42Main.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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | package Problem31; import java.util.Scanner; public class Main { // 숫자를 받아서 리턴하는 함수를 생성함 public static int function(int number) { // 팩토리얼한 수를 저장할 변수 int total = number; for (int i = 1; i < number; i++) { total *= i; } return total; } public static void main(String[] args) { // 입력한 수의 팩토리얼 구하기 // 숫자 입력받기 System.out.println("숫자를 입력하세요."); int number; Scanner scan = new Scanner(System.in); number = scan.nextInt(); // 위에서 팩토리얼을 계산한 수를 저장할 변수. int total = function(number); System.out.printf("결과 : %d", total); } } | cs |
출력 결과
출처
https://www.youtube.com/watch?v=JyaK14AhGm4&list=PLVoihNyHW4xkm_KJ8_N8X7F6EQP4uSRyR&index=32
'Algorithm > 풀었던문제' 카테고리의 다른 글
알고리즘 기초 - 32 ( 누적합, 함수 ) (0) | 2019.12.30 |
---|---|
알고리즘 기초 - 30 ( 더하기 & 마이너스 ) (0) | 2019.12.30 |
알고리즘 기초 - 29 ( 음계 ) (0) | 2019.12.30 |
알고리즘 기초 - 28 ( 진수 변환 ) (2) | 2019.12.30 |
알고리즘 기초 - 27 ( 달팽이 출력 ) (0) | 2019.12.29 |