
Call by Value 예시 package Sample // 어떻게 보면 자바에서는 그냥 통칭하여 call by value라고 할 수도 있음. /* 예시, swap이란 함수를 써서 값을 바꾸기만 했으면 좋겠다. */ public class CallbyExample { static void swap(int a, int b) { int temp = a; a = b; b = temp; System.out.println(a); // 20 출력 System.out.println(b); // 10 출력 } public static void main(String[] args) { int a = 10; int b = 20; swap(a, b); System.out.println(a); // 10 출력 System.o..
소스코드 public class Q2 { static String inputString() { Scanner sc = new Scanner(System.in); System.out.print("문자열 입력하세요 : "); return sc.next(); } static int inputNum() { Scanner sc = new Scanner(System.in); System.out.print("1. 짝수 2 홀수 : "); return sc.nextInt(); } static void printHJ(int num,String str) { for(int i = num-1;i
소스코드 public class Q3 { // 주고 안받고 static int makeRandom() { Random r = new Random(); return r.nextInt(26); } // 주고 받고 static int intSum(int r) { return 65 + r; } // 주고 받고 static char makeChar(int result) { return (char)result; } // 안주고 안받고 static void run() { String result = ""; for(int i = 0;i
소스코드 package Day12; import java.util.Scanner; public class Q1_1 { static int add(int a, int b) { return a + b; } static void minus(int a, int b) { System.out.println("결과값 : "+(a-b)+" 입니다."); } static int mul() { Scanner sc = new Scanner(System.in); int[] array =input(sc); return array[0] * array[1]; } static void div() { Scanner sc = new Scanner(System.in); int[] array =input(sc); System.out.pri..

1. 리턴값은 다른 메서드가 main 메서드에게 주는 값이다 -> 좀 더 정확하게는 호출 당한 메서드가 호출한 메서드에게 주는 값이다. public class _01 { static int addTwoNumbers(int a, int b) { return a+b; } public static void main(String[] args) { int sum = addTwoNumbers(100,200); System.out.println(addTwoNumbers(100,200)); } } 이런 경우는 main 에게 준다고 할 수 있지만, public class _01 { static int addTwoNumbers(int a, int b) { return a+b; } static void hello() { a..

이 모양이 나오도록 2차원 배열 활용하기 풀이 IDEA * 열이 증가하고 -> 행이 증가하고 / 또는, 열이 감소하고 -> 행이 감소하고 ... => 이 논리가 한 세트가 될 수 있다. * 이 두 개가 하나의 쌍으로 동작한다. * 한 번 반복 할 때마다 방향이 바뀌어야 한다. ** 방향 바꾸는 가장 간편한 방법이 switch를 이용하는 것! (변수 선언해서 활용하는 방법이겠지.) *** 이 sw는 부호를 바꾸는 역할만 수행하면 된다. 즉 열이 증가하고 -> 행이 증가하고 // 스위치 // 열이 감소하고 -> 행이 감소하고 이 로직. 반복 횟수를 나타내는 변수 k도 선언해서, k--;를 반복이 끝날 때마다 해주고, k==0 이 되면 break. 그런데 이 세트가 왜 가운데에 있는가? 열과 행이 하나의 세트..
정리하자면, 피라미드와 다이아몬드는 일종의 idea가 꽤 필요한 작업이다. 피라미드 public class MakeStar04Sample { public static void main(String[] args) { /* 일단 피라미드를 그리려면 모양을 쪼개서 살펴보자 왼쪽 직각삼각형과 오른쪽 직각삼각형 혹은 가운데를 기준으로 왼쪽과 오른쪽에 하나씩 더 찍어주면, 완성이 된다 뭐 요런 느낌으로다가. */ //4.피라미드 for (int i = 0; i = 0; j--) { // 4 3 2 1 0 if (i < j) { //4 3 2 1 / 4 3 2 /4 3 / 4 System.out.print(" "); } else { //0..