โ
๋ฌธ์ ์ฌ์ฉ์์๊ฒ ๋ณ์ ์๋ฅผ ์
๋ ฅ๋ฐ์ ๋ฐฐ์ด ์ธ๋ฑ์ค์ ์ ๋งํผ ๋ณ ์ฐ๊ธฐ โ
์ฝ๋ import java.util.Scanner; public class bonus04 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[] cc = new int[5]; // ๋ฐ๋ณต๋ฌธ์ผ๋ก ์ซ์์
๋ ฅ ๋ฐ๊ธฐ for (int i = 0; i < cc.length; i++) { System.out.print(i + "๋ฒ์งธ ๋ณ์ ์ : "); cc[i] = sc.nextInt(); } // ๋ฐฐ์ด ์ํ for (int i = 0; i < cc.length; i++) { System.out.print(cc[i] + ":"); // ๋ณ ์ถ๋ ฅ fo..
์ถ๋ ฅ
โ
๋ฌธ์ ๊ณ์ฐ๊ธฐ ๋ง๋ค๊ธฐ โ
์ถ๋ก ๊ณผ์ ๋ ๊ฐ์ ์ ์์ ์ฐ์ฐ์๋ฅผ ์
๋ ฅ ๋ฐ์์ ํด๋น ์ฐ์ฐ์ ์ํํ๋ ๊ฐ๋จํ ๊ณ์ฐ๊ธฐ ๊ตฌํ ์ฝ๋์ด๋ค. ๋งค๊ฐ๋ณ์๊ฐ ์ด 3๊ฐ์ด๊ณ , int ํ์ผ๋ก ๊ฒฐ๊ณผ๋ฅผ return ํด ์ฃผ๋ฉด ๋๋ ์ฌ์ด ๋ฌธ์ ์ด๋ค. ๋ฉ์๋๋ Main ์์ญ ๋ฐ์์ ๋ง๋ค์ด์ฃผ๊ณ ๊ฒฐ๊ณผ ๊ฐ๋ง Main์์ญ ์์์ ์ถ๋ ฅํด์ฃผ๋ฉด ๋๋ค. โ
์ฝ๋ public class bonus03 { public static void main(String[] args) { System.out.println(cal(4, 7, '*')); } public static int cal(int num1, int num2, char op) { if (op == '+') { return num1 + num2; } if (op == '-') { return num1..
โ
๋ฌธ์ A, B ์ซ์๋ฅผ ์
๋ ฅ๋ฐ๋๋ค.A-B๋ฅผ ์ถ๋ ฅํ๋ค.A์ B๊ฐ ๋ชจ๋ 0์ ์
๋ ฅ ๋ฐ์ผ๋ฉด ํ๋ก๊ทธ๋จ์ด ์ข
๋ฃ๋๋ค. โ
์ฝ๋ import java.util.Scanner; public class bonus01 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (true) { System.out.print("A ์
๋ ฅ >> "); int num1 = sc.nextInt(); System.out.print("B ์
๋ ฅ >> "); int num2 = sc.nextInt(); System.out.println("๊ฒฐ๊ณผ >> " + (num1 - num2)); if (num1 == 0 && num2 == 0) { brea..
โ
๋ฌธ์ ๊ฐ ์ถ๋ ฅํ๊ธฐโ ์ด์ค์ผ์ดํ ์ฝ๋(Escape Sequance)๋ฅผ ์ดํดํ๊ธฐ ์ํ ๋ฌธ์ โ๐ฅ ์
๋ ฅ ์์ โ๐ฅ ์ถ๋ ฅ ๊ฐ๋ฅผ ์ถ๋ ฅํ๋ค โ ๐ก ํ์ด ์ด ๋ฌธ์ ๋ ๊ณ ์์ด ๋ฌธ์ ๋ ๋งค์ฐ ์ ์ฌํ๋ค. ์ด์ค์ผ์ดํ ์ฝ๋ ์ ๋ฆฌ โผ
โ
๋ฌธ์ ๋ฌธ์์ด ํํ์ 2์ง์๋ฅผ ์
๋ ฅ๋ฐ์ 10์ง์๋ก ๋ฐ๊พธ๋ ํ๋ก๊ทธ๋จ์ ์์ฑํ์์ค. โ
์ฝ๋ import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str = sc.next(); int base = 1; int result = 0; for (int i = str.length()-1 ; i >= 0; i--) { if(str.charAt(i) == '1'){ result += base; } base *= 2; } System.out.println(result); } } โ
์ด์ง์๋ฅผ ์ญ์ง์๋ก ๋ฐ๊พธ๋ ๋ฒ ์ด์ง์๋ 0๋๋ 1๋ก ์ด๋ฃจ์ด์ ธ ..
โ
๋ฌธ์ ๊ทธ๋ฆผ๊ณผ ๊ฐ์ด ๋์('_') ๋ฌธ์๋ก ๊ตฌ์ฑ๋ ํํ์ ์ซ์๋ฅผ ์ฃผ์ด์ง ์ซ์์ ๊ฐ์ด ์ถ๋ ฅํ๊ณ ์ถ์ ๋ ์ฌ์ฉ๋๊ธฐ ๋๋ ๋์์ ๊ฐ์๋ฅผ ์ถ๋ ฅํ๋ ํ๋ก๊ทธ๋จ์ ์์ฑํ๋ผ. โ
์ฝ๋ 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 < nums.length(); i++) { r..
โ
๋ฌธ์ [์
๋ ฅ] 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 i = 0; i < n; i++) { System.out.print((i+1) + "๋ฒ..
โ
๋ฌธ์ ์๋์ ๊ฐ์ 2์ฐจ์ ๋ฐฐ์ด์ ์ผ์ชฝ์ผ๋ก 90๋ ํ์ ํ์ฌ ์ถ๋ ฅํ์์ค. โ
์ฝ๋ public class Main { public static void main(String[] args) { int[][] num = new int[5][5]; int count = 1; for (int i = 0; i < num.length; i++) { for (int j = 0; j < num.length; j++) { num[i][j] = count++; } } // ์๋ณธ๋ฐฐ์ด ์ถ๋ ฅ for (int i = 0; i < num.length; i++) { for (int j = 0; j < num.length; j++) { System.out.print(num[i][j] + "\t"); } System.out.printl..