Development/Java(855)
-
ConsoleOutputEx01 - System.out.print vs System.out.println
System.out.print vs System.out.println 소스코드 public class ConsoleOutputEx01 { public static void main(String[] args) { Friend myFriend1=new Friend("홍길동"); Friend myFriend2=new Friend("일지매"); //인스턴스의 참조값을 전달받아서 출력됩니다. System.out.println(myFriend1); System.out.println(myFriend2); System.out.print("출력이 "); System.out.print("종료되었습니다."); System.out.println(""); System.out.print("끝"); } } class Friend ..
-
System.out.println( )
System.out.println( ) System.out.println()은 Sytem 클래스의 멤버 out이 참조하는 인스턴스의 println 메소드를 호출하는 문장 Systemoutprintln클래스 이름static 참조 변수메소드 System java.lang 패키지에 묶여있는 클래스의 이름 import java.lang.*; 자동 삽입되므로 System이란 이름을 직접 쓸 수 있습니다. out staitc 변수이되 인스턴스를 참조하는 참조변수 PrintStream이라는 클래스의 참조변수 public class System{ public static final PrintStream out; }static final로 선언되어 있어, 인스턴스의 생성 없이 system.out 이라는 이름으로 접근 가..
-
ResursiveEx02-잘못된 재귀 메소드 정의
잘못된 재귀 메소드 정의 종료조건이 만독되지 않으면 무한 루프에 빠질 수 있습니다. 종료조건 및 종료조건의 검사위치를 로직 상 점검 하시기 바랍니다. 종료조건은 메소드의 실행과 재귀 메소드 실행되는 사이에 존재해야 됩니다. 소스코드 public class ResursiveEx02 { public static void main(String[] args) { showJava(3); } /*잘못된 재귀 메소드 정의*/ /* public static void showJava(int cnt) { System.out.println("JAVA "); //재귀메소드 호출 showJava(cnt--); //Exception in thread "main" java.lang.StackOverflowError //종료조건 i..
-
RecursiveEx01-재귀 함수 호출
재귀 함수 호출 함수 코드의 복사본이 하나 더 생성해어 실행되는 것이 재귀입니다. 컴퓨터 시스템factorial(3)리턴 결과 3*factoral(2) = 6 2*factoral(1) = 2 1 소스코드 public class RecursiveEx01 { public static void main(String[] args) { System.out.println("3 factorial: " + factorial(3)); System.out.println("7 factorial: " + factorial(7)); System.out.println("12 factorial: " + factorial(12)); } public static int factorial(int n) { if(n==1) return 1..
-
VariableScopeEx01-변수의 범위 확인
변수의 범위 확인 소스코드
-
FunctionEx04-키워드 return의 역할
키워드 return의 역할 return 키워드 역할 값의 반환 메소드 종료 소스코드 public class FunctionEx04 { public static void main(String[] args) { dividedby(4, 2); dividedby(6, 2); dividedby(8, 0); int returnResult = divide(6, 2); System.out.println("리턴된 결과: " + returnResult); } /* return 키워드 역할 • 값의 반환 • 메소드 종료 */ public static void dividedby(int num1, int num2) { if(num2==0) { System.out.println("(알림)0값으로 나눌 수 없습니다."); //메소..