제 1유형 | 제 2유형 | 제3유형 | 제4 유형 |
input x output x | input o output x | input x output o | input o output o |
Just 출력 public static void test01() { Random rand=new Random(); int num=rand.nextInt(10)+1; System.out.println(num); |
public static void test02(int num) { if(num%2==1) { System.out.println("홀수"); } else { System.out.println("짝수"); } } |
public static int test03() { Random rand=new Random(); int num=rand.nextInt(10)+1; return num; } |
public static int test04(int a,int b) { return a>b?a:b; } |
<실제로 함수 활용해보기>
코딩과정
1. 복붙하는 과정이 있다
2. 함수제작
3. 코드 복붙
4. 에러발생하면 원인파악
5. 원인을 파악해 input 생성
6. output 확인
7. main() 에서 완성된 함수 호출!!
하나의 예)
전체출력 함수 만들기 //데이터정보 출력
public static void allprint (int[] datas) {
for(int v:datas) {
System.out.println(v+ " ");
}
System.out.println();
}
//이렇게 호출하면 메인에서 쓸 수 있는 함수가 줄어듦
if (action==2) {
test02(datas);
}
'JAVA' 카테고리의 다른 글
저는 이제 노션으로 떠납니다 안녕 (0) | 2025.04.11 |
---|---|
JAVA- 객체 지향 언어임을 보여주는 문제 예제 (1) | 2025.01.11 |
자바- 객체 지향 언어의 특징 (0) | 2025.01.10 |
버블배열 (BUBBLE) (0) | 2025.01.04 |
배열문제 ① (0) | 2025.01.02 |