Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- 상속
- 스타일보험
- Android
- 쿠키
- 안드로이드
- 미니게임
- kotlin
- 버전일치
- java
- Spring
- SQL
- 숫자
- 시큐어코딩
- 답글
- 게시판
- 함수
- React
- webpack
- FIle
- 스프링
- 코틀린
- parcel
- snowpack
- java#왕초보
- 왕초보
- 오버라이드
- git
- degit
- sub query
- Spinner
Archives
- Today
- Total
YSHUSH
Method1 본문
˙ function : 함수. 독립적
˙ method : class에 소속된 함수.
˙ 형식:
parameter = 인수, 인자, 게타(getter)
돌아오는 값의 자료형 함수명(들어가는 값의 자료형 변수, 들어가는 값의 자료형 변수, ...) {
처리
return 값; // return value
}
void -> 자료형이 없는 것
int i = functionName('A'); // 'A' == argument
System.out.println(i);
String st = "abcDEF";
String upst = toUpperCase(st);
System.out.println(upst);
functionName1();
functionName2(6.2, 0);
int r = functionName3();
String str = "hello";
int len = str.length();
System.out.println( len );
char c = str.charAt(1);
System.out.println( c );
int array[] = {11, 22, 33};
int arrAlias[]; // 배열 복사
arrAlias = array; // 주소 복사
arrAlias[1] = 27;
System.out.println(arrAlias[1]);
System.out.println(array[1]);
System.out.println(arrAlias);
System.out.println(array);
int arrayNum[] = { 1, 2, 3, 4, 5 }; // 값이 넘어감
functionName4(arrayNum[0], arrayNum[1], arrayNum[2], arrayNum[3], arrayNum[4]);
System.out.println(Arrays.toString(arrayNum)); // result: 1, 2, 3, 4, 5
functionName5(arrayNum);
System.out.println(Arrays.toString(arrayNum)); // result: 2, 4, 6, 8, 10
int arr[] = functionName6(arrayNum);
System.out.println(Arrays.toString(arr));
}
static int[] functionName6(int array[]) { // 배열 자체가 넘어가면 return을 받지 않아도 문제가 없을 수 있다.
for (int i = 0; i < array.length; i++) {
array[i] = array[i] * 2;
}
return array;
}
// 주소를 할당
static void functionName5(int array[]) { // 배열 자체(자신)가 넘어감
for (int i = 0; i < array.length; i++) { // int array[]는 나오는 값으로 input값이 아니다
array[i] = array[i] * 2;
}
}
// value 값을 할당
static void functionName4(int a1, int a2, int a3, int a4, int a5) {
a1 = a1 * 2;
a2 = a2 * 2;
a3 = a3 * 2;
a4 = a4 * 2;
a5 = a5 * 2;
}
static int functionName3() {
System.out.println("functionName3() 호출");
return 3;
}
static void functionName2(double d, int n) {
double result;
System.out.println("functionName2(double d, int n) 호출");
if( n == 0 ) {
System.out.println("계산할 수 없습니다");
return;
}
result = d / n;
System.out.println("결과값:" + result);
}
static void functionName1() {
System.out.println("functionName1() 호출");
return; // 원래는 있어야 하지만 return 값이 없으므로 생략 가능
}
static int functionName(char c) { // parameter
System.out.println("functionName(char c) 호출");
return 1;
}
static String toUpperCase(String str) {
String s = "";
for (int i = 0; i < str.length(); i++) {
int n = str.charAt(i);
if(n >= 97 ) {
n = n - 32;
}
s = s + (char)n;
}
return s;
}
}