반응형 학습65 3. 연산자(2) - 메소드 public class MethodExample { // main메소드 // String[] args 매개변수 // (매개변수 타입) (매개변수이름) // 매개변수 = 인수 = 인자 = 파라미터 public static void main(String[] args) { System.out.println("메인메소드를 실행함"); String greeting = "안녕?"; // 문자열 데이터 System.out.println("proceed메소드를 호출합니다"); proceed(greeting); System.out.println("메인메소드 끝"); } public static void proceed(String message) { // message = "안녕?" 할당됨 System.out... 2022. 9. 28. 3. 연산자(1) - 연산자 종류 public class OperationPriority { public static void main(String[] args) { System.out.println("12를 5로 나누었을 때 나머지 : " + 12 % 3); // 산술연산자 연산방향 : 왼쪽에서 오른쪽 int num = 9 * 4 / 3 % 5; System.out.println("num=" + num); // 대입연산자의 연산 방향 : 오른쪽에서 왼쪽 int a, b, c; a=b=c=5; System.out.println("a=" + a); System.out.println("b=" + b); System.out.println("c=" + c); } } 값 12를 5로 나누었을 때 나머지 : 0 num=2 a=5 b.. 2022. 9. 28. 3. 타입 변환 - 타입 변환 - 자동 타입 변환 public class PromotionExample { public static void main(String[] args) { byte byteValue = 10; // 2byte 정수 int intValue = byteValue; // 자동타입변환 byte -> int System.out.println(intValue); char charValue = '가'; // 2byte intValue = charValue; // 재할당 44032 System.out.println(intValue); intValue = 500; // 4byte long longValue = intValue; // 8byte int -> long System.out.println(longVal.. 2022. 9. 27. 2. 데이터 타입 - 기본 타입 - 데이터의 크기 단위 - 기본타입 선언 및 초기화 public class PrimitiveType { public static void main(String[] args) { // 정수 타입 byte byteValue = 100; char chValue = 'F'; short shValue = 101; int intValue = 124; long longvalue = 1535; // 실수 타입 float floatValue1 = 10.111f; float floatValue2 = 3.14F; // 접미사 (f, F)생략 불가능 double doubleValue1 = 3.141592D; double doubleValue2 = 3.141592d; double doubleValue3 = 3.1.. 2022. 9. 27. 이전 1 ··· 13 14 15 16 17 다음 반응형