Banner

My Tech Blog (ํ’€์ด)

โœ… ๋ฌธ์ œ1๋ณด๋‹ค ํฐ ์ •์ˆ˜(N)์„ ์ž…๋ ฅํ•˜๋ฉฐ N!๊ฐ’์„ ๊ตฌํ•˜์‹œ์˜ค.*ํŒฉํ† ๋ฆฌ์–ผ์ด๋ž€ N์˜ ์ˆ˜๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ๋ชจ๋“  ์–‘์˜ ์ •์ˆ˜์˜ ๊ณฑex) 3! = 1 x 2 x 3 => 6โœ… ์ฝ”๋“œpublic class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("์ž…๋ ฅ : "); int n = sc.nextInt(); // ๋ณ€์ˆ˜ ์ดˆ๊ธฐํ™” int factorial = 1; // n๋ถ€ํ„ฐ 1๊นŒ์ง€์˜ ๋ชจ๋“  ์–‘์˜ ์ •์ˆ˜๋ฅผ ๊ณฑํ•จ for (int i = 1; i  โœ… ์ถ”๋ก ๊ณผ์ •int factorial = 1;: ํŒฉํ† ๋ฆฌ์–ผ ๊ฐ’์„ ..
โœ… ๋ฌธ์ œ๋žœ๋ค์œผ๋กœ ์ •์ˆ˜ 2๊ฐœ๋ฅผ ๋ฝ‘์•„ ์•„๋ž˜์™€ ๊ฐ™์ด ์ถœ๋ ฅ์‚ฌ์šฉ์ž๋Š” ๋‘ ์ˆ˜์˜ ํ•ฉ์„ ์ž…๋ ฅ๋‘ ์ˆ˜์˜ ํ•ฉ๊ณผ ์ž…๋ ฅํ•œ ์ˆ˜๊ฐ€ ์ผ์น˜ํ•˜๋ฉด "Success", ๋‘ ์ˆ˜์˜ ํ•ฉ๊ณผ ์ž…๋ ฅํ•œ ์ˆ˜๊ฐ€ ์ผ์น˜ํ•˜์ง€ ์•Š์œผ๋ฉด "Fail"์„ ์ž…๋ ฅ*๊ธฐํšŒ๋Š” 5๋ฒˆ! 5๋ฒˆ ํ‹€๋ฆฌ๋ฉด GAME OVER โœ… ์ฝ”๋“œimport java.util.Random;import java.util.Scanner;public class Main { public static void main(String[] args) { Random rd = new Random(); Scanner sc = new Scanner(System.in); int cnt = 0; while (true) { int num1 = rd.nextInt(10) + 1; int num2 = rd.nextIn..
โœ… ๋ฌธ์ œ์Šค๋งˆํŠธ๋ฏธ๋””์–ด์ธ์žฌ๊ฐœ๋ฐœ์›์˜ ์ธ์Œค์ด Java ์‹œํ—˜๋ฌธ์ œ๋ฅผ ์ฑ„์ ํ•˜๊ณ  ์žˆ๋‹ค.๋ฌธ์ œ๋งˆ๋‹ค 'o' ๋˜๋Š” 'x'๋กœ ํ‘œ์‹œ๊ฐ€ ๋˜์–ด ์žˆ๋Š”๋ฐ ์ ์ˆ˜๋ฅผ ๋งค๊ธฐ๋Š” ๋ฐฉ์‹์ด ํŠน์ดํ•˜๋‹ค.'o'๋Š” ์ ์ˆ˜๊ฐ€ ๋ˆ„์ ๋˜๋Š” ๋ฐฉ์‹์œผ๋กœ ์ฑ„์ ๋˜๋Š”๋ฐ ์ด์ „๋ถ€ํ„ฐ ์ž์‹ ์„ ํฌํ•จํ•œ ์—ฐ์†๋œ 'o'์˜ ๊ฐœ์ˆ˜ ๋งŒํผ์˜ ์ ์ˆ˜๋กœ ์ฑ„์ ์ด ๋ฉ๋‹ˆ๋‹ค.์˜ˆ๋ฅผ ๋“ค์–ด 'oooxoo'๋ผ๋Š” ํ‘œ์‹œ๊ฐ€ ์žˆ๋‹ค๋ฉด ์ˆœ์„œ๋Œ€๋กœ 1+2+3+0+1+2=9 ์œผ๋กœ ์ด์ ์ด ๊ณ„์‚ฐ๋ฉ๋‹ˆ๋‹ค.ํ•™์ƒ์ด ํ‘ผ ์‹œํ—˜์ง€์— ์ •๋‹ต, ์˜ค๋‹ต ์—ฌ๋ถ€๊ฐ€ ํ‘œ์‹œ๋˜์–ด ์žˆ์„ ๋•Œ ์ด์ ์„ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์„ธ์š”. โœ… ์ฝ”๋“œimport java.util.Scanner;public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String c..
โœ… ๋ฌธ์ œ(์„ธ ์ž๋ฆฌ ์ˆ˜) * (์„ธ ์ž๋ฆฌ ์ˆ˜)๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๊ณ„์‚ฐ๋œ๋‹ค.(1),(2)๋ฒˆ์„ ์ž…๋ ฅ ๋ฐ›์•„ ๊ฒฐ๊ณผ ํ™”๋ฉด์ฒ˜๋Ÿผ (3), (4), (5), (6)๋ฒˆ์„ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜คโœ… ์ฝ”๋“œimport java.util.Scanner;public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("์ฒซ ๋ฒˆ์žฌ ์ˆซ์ž ์ž…๋ ฅ >> "); int num1 = sc.nextInt(); System.out.print("๋‘ ๋ฒˆ์งธ ์ˆซ์ž ์ž…๋ ฅ >> "); int num2 = sc.nextInt(); int cal1 = num1 * (num2 % 10); // num2์˜ ์ผ์˜์ž๋ฆฌ์ˆ˜..
โœ… ๋ฌธ์ œ๊ทธ๋ฆผ๊ณผ ๊ฐ™์ด ๋Œ€์‹œ('_') ๋ฌธ์ž๋กœ ๊ตฌ์„ฑ๋œ ํ˜•ํƒœ์˜ ์ˆซ์ž๋ฅผ ์ฃผ์–ด์ง„ ์ˆซ์ž์™€ ๊ฐ™์ด ์ถœ๋ ฅํ•˜๊ณ  ์‹ถ์„ ๋•Œ ์‚ฌ์šฉ๋˜๋Š” ๋Œ€์‹œ์˜ ๊ฐœ์ˆ˜๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜๋ผ.โœ… ์ฝ”๋“œimport java.util.Scanner;public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[] c = { 6, 2, 5, 5, 4, 5, 6, 3, 7, 6 }; System.out.print("์ฒซ์ž๋ฆฌ 0์„ ์ œ์™ธํ•œ ์ˆซ์ž๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š” >> "); String nums = sc.nextLine(); int result = 0; for (int i = 0; i > " + result); sc.close()..
โœ… ๋ฌธ์ œ ์ž…๋ ฅ๋œ ๊ฐ’ ๊ทธ๋Œ€๋กœ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ ์งœ๊ธฐ โ€‹๐Ÿ“ฅ ์ž…๋ ฅ ์ž…๋ ฅ์ด ์ฃผ์–ด์ง„๋‹ค. ์ž…๋ ฅ์€ ์ตœ๋Œ€ 100์ค„๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๊ณ , ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž, ๋Œ€๋ฌธ์ž, ๊ณต๋ฐฑ, ์ˆซ์ž๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ ์žˆ๋‹ค. ๊ฐ ์ค„์€ 100๊ธ€์ž๋ฅผ ๋„˜์ง€ ์•Š์œผ๋ฉฐ, ๋นˆ ์ค„์ด ์ฃผ์–ด์งˆ ์ˆ˜๋„ ์žˆ๊ณ , ๊ฐ ์ค„์˜ ์•ž ๋’ค์— ๊ณต๋ฐฑ์ด ์žˆ์„ ์ˆ˜๋„ ์žˆ๋‹ค. โ€‹๐Ÿ“ฅ ์ถœ๋ ฅ ์ž…๋ ฅ ๋ฐ›์€ ๊ทธ๋Œ€๋กœ ์ถœ๋ ฅํ•œ๋‹ค. โ€‹ ๐Ÿ’ก ํ’€์ด 11718๋ฒˆ๊ณผ ์œ ์‚ฌํ•œ ๋ฌธ์ œ๋กœ ๋„์–ด์“ฐ๊ธฐ๋ฅผ ํฌํ•จํ•œ ๋ฌธ์ž์—ด์„ ์ž…๋ ฅ๋ฐ›์•„ ๊ทธ๋Œ€๋กœ ์ถœ๋ ฅํ•ด์ฃผ๋ฉด ๋œ๋‹ค. ์ž…๋ ฅ์ด ๋ช‡ ์ค„ ๋“ค์–ด์˜ค๋Š”์ง€ ์ฃผ์–ด์ง€์ง€ ์•Š์•˜๊ธฐ ๋•Œ๋ฌธ์—, ๊ณ„์† ์ž…๋ ฅ์ด ๋“ค์–ด์˜จ๋‹ค๊ณ  ๊ฐ€์ •ํ•˜๊ณ  while-loop๋ฅผ ์ด์šฉํ•ด ์ž…๋ ฅ์„ ๋ฐ›๊ณ , ์ž…๋ ฅ๋ฐ›์€ ๊ฒƒ์ด ์—†์œผ๋ฉด loop์„ ์ข…๋ฃŒํ•ด ์ฃผ๋ฉด ๋œ๋‹ค. input()๊ณผ sys.stdin.readlines()๋ฅผ ์ด์šฉํ•˜์—ฌ ๋‘ ๊ฐ€์ง€๋กœ ํ’€์ดํ–ˆ๋‹ค. โœ… 1. Buffered..
โœ… ๋ฌธ์ œ ์ž…๋ ฅ๋œ ๊ฐ’ ๊ทธ๋Œ€๋กœ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ ์งœ๊ธฐ โ€‹๐Ÿ“ฅ ์ž…๋ ฅ ์ž…๋ ฅ์ด ์ฃผ์–ด์ง„๋‹ค. ์ž…๋ ฅ์€ ์ตœ๋Œ€ 100์ค„๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๊ณ , ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž, ๋Œ€๋ฌธ์ž, ๊ณต๋ฐฑ, ์ˆซ์ž๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ ์žˆ๋‹ค. ๊ฐ ์ค„์€ 100๊ธ€์ž๋ฅผ ๋„˜์ง€ ์•Š์œผ๋ฉฐ, ๋นˆ ์ค„์€ ์ฃผ์–ด์ง€์ง€ ์•Š๋Š”๋‹ค. ๋˜, ๊ฐ ์ค„์€ ๊ณต๋ฐฑ์œผ๋กœ ์‹œ์ž‘ํ•˜์ง€ ์•Š๊ณ , ๊ณต๋ฐฑ์œผ๋กœ ๋๋‚˜์ง€ ์•Š๋Š”๋‹ค. โ€‹๐Ÿ“ฅ ์ถœ๋ ฅ ์ž…๋ ฅ ๋ฐ›์€ ๊ทธ๋Œ€๋กœ ์ถœ๋ ฅํ•œ๋‹ค. โ€‹ ๐Ÿ’ก ํ’€์ด ์ฒ˜์Œ์—๋Š” ์—ฅ? ์ด๊ฒŒ ์ •๋‹ต๋ฅ  30ํผ์„ผํŠธ ๋ฐ–์— ์•ˆ ๋œ๋‹ค๊ตฌ? ์ƒ๊ฐํ–ˆ๋Š”๋ฐ ๋‚˜๋„ ํ‹€๋ ธ๋‹ค. ๋ณดํ†ต์€ ๋ฌธ์ œ์—์„œ n๊ฐœ์˜ ์ค„์— ์ž…๋ ฅ์„ ๋ฐ›์œผ๋ผ๋Š” ๋ฐ˜๋ณต ํšŸ์ˆ˜๊ฐ€ ์ฃผ์–ด์ง€๋Š”๋ฐ ์ด ๋ฌธ์ œ์—์„œ๋Š” n์„ ์•Œ๋ ค์ฃผ์ง€ ์•Š๋Š”๋‹ค. ์ž…๋ ฅ๊ฐ’์ด ๋ช‡ ๋ฒˆ ์ฃผ์–ด์ง€๋Š”์ง€๋Š” ๋ชจ๋ฅด์ง€๋งŒ ์ž…๋ ฅ๋œ ๊ฐ’ ๊ทธ๋Œ€๋กœ ์ถœ๋ ฅํ•ด์•ผํ•˜๋Š” ๋ฌธ์ œ์ด๋‹ค. ๊ทธ๋ž˜์„œ while๋ฌธ์„ ๋Œ๋ ค์ฃผ๊ณ  ์กฐ๊ฑด์„ ๋งŒ์กฑํ•˜๋ฉด break๋ฅผ ๊ฑธ์–ด ์ฃผ๋Š” ๊ฒŒ ํ•ต์‹ฌ์ด๋‹ค. input..
โœ… ๋ฌธ์ œ  [์ž…๋ ฅ]1. N๊ณผ X๋ฅผ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค.2. N๊ฐœ์˜ ์ •์ˆ˜๋ฅผ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค. (๋ฐ˜๋ณต๋ฌธ) [์ถœ๋ ฅ]3. N๊ฐœ์˜ ์ˆซ์ž ์ค‘ X๋ณด๋‹ค ์ž‘์€ ์ˆ˜๋งŒ ์ถœ๋ ฅํ•œ๋‹ค. โœ… ์ฝ”๋“œimport java.util.Scanner;public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("N ์ž…๋ ฅ >> "); int n = sc.nextInt(); System.out.print("X ์ž…๋ ฅ >> "); int x = sc.nextInt(); int[] nums = new int[n]; for (int ..
์ธ์ ˆ๋ฏธ์˜€๋˜๊ฒƒ
'ํ’€์ด' ํƒœ๊ทธ์˜ ๊ธ€ ๋ชฉ๋ก (11 Page)
์ƒ๋‹จ์œผ๋กœ