Eggs Sunny Side Up
본문 바로가기

Algorithm153

팩토리얼(N!)값을 출력 import java.util.Scanner; public class P_21 { public static void main(String[] args) { // 1보다 큰 정수(N)를 입력하여 N!값을 구하시오. // *팩토리어이란 N의 수보다 작거나 같은 모든 양의 접의 곱 // ex) 3! = 1*2*3* => 6 Scanner sc = new Scanner(System.in); System.out.print("입력 : "); int num = sc.nextInt(); int mul = 1; for(int i = 1; i 2023. 3. 4.
[Java Festival] 배열 선언 후 랜덤수로 초기화하고 가장 큰 수와 가장 작은 수를 출력 import java.util.Random; public class P_19 { public static void main(String[] args) { // 8칸 크기의 배열을 선언하고 랜덤수로 초기화 한 후 // 가장 큰 수와 작은 수를 각각 출력하시오. Random rd = new Random(); int[] array = new int[8]; System.out.print("배열에 있는 모든 값 : "); for(int i = 0; i < array.length; i++) { array[i] = rd.nextInt(100)+1; System.out.print(array[i]+" "); } System.out.println(); int max = array[0]; System.out.print("가.. 2023. 3. 2.
[Java Festival] 빈칸과 *(별)로 결과 출력 package 배열; import java.util.Scanner; public class Ex_연습장 { public static void main(String[] args) { // 방법 1. for (int i = 1; i i - 1; k--) { System.out.print(" "); } for (int j = 1; j = i; k--) { System.out.print(" "); } for (int j = 1; j 2023. 3. 2.
[Java Festival] 랜덤으로 2가지 정수를 뽑은 후 합 구하기. 5번 이상 틀리면 게임오버. import java.util.Random; import java.util.Scanner; public class P_16 { public static void main(String[] args) { // 랜덤으로 정수 2개를 뽑아 아래와 같이 출력 // 사용자는 두 수의 합을 입력 // 두 수의 합과 입력한 수가 일치하면 "SUCCESS" // 두 수의 합과 입력한 수가 일치하지 않으면 "FAIL"을 출력 // 기회는 5번! 5번 틀리면 GAME OVER Random rd = new Random(); Scanner sc = new Scanner(System.in); int cnt = 0; while(true) { int num1 = rd.nextInt(10)+1; int num2 = rd.nextInt.. 2023. 3. 2.
[Java Festival] 행 개수를 입력하여 역삼각형 모양으로 *(별) 출력 import java.util.Scanner; public class P_15 { public static void main(String[] args) { // 행 개수를 입력 받아 다음과 같이 삼각형을 출력하시오. Scanner sc = new Scanner(System.in); System.out.print("행 개수 : "); int num = sc.nextInt(); for (int i = 1; i i; k--) { System.out.print("*"); } System.out.println(); } } } 2023. 3. 2.
[Java Festival] 행 개수를 입력하여 *(별) 출력 import java.util.Scanner; public class P_14 { public static void main(String[] args) { // 행 개수를 입력 받아 다음과 같이 삼각형을 출력하시오. Scanner sc = new Scanner(System.in); System.out.print("행 개수: "); int num = sc.nextInt(); for (int i = 1; i 2023. 3. 2.