[이것이 자바다] Method

    public class ArrTest {
    	public static void arrArg(int[] a/*매개변수*/) {//arrArg의 메서드를 만듦(메서드의 정의)
    		//배열 뿌리기
    		
    		for(int j=0; j<a.length; j++) {
    			System.out.println(j+a[j]);
    		}
    		
    	}
    	public static void main(String[] args) {
    		int[] ary = {10,20,30,40,50};
    		for(int i=0; i<ary.length; i++) {
    			//System.out.print(ary[i]); 
    			}
    		int[] ary1;
    		ary = new int[] {50,60,70,80,90,100};//초기화
    
    		arrArg(new int[] {1,2,3});
    	}
    	
    	
    }
    

    public static void main(String[] args) {}

    • 클래스 내부에 존재하는 영역으로 해당 영역안에 데이터들을 입력하여 처리한다

    public static void arrArg(int[] a/매개변수/) {//arrArg의 메서드를 만들 수 있다(메서드의 정의)}

    두개의 매개변수를 작는 메서드 정의와 호출

    package org.name.calc01;
    
    import java.util.Scanner;
    
    public class mathod {
    	public static void plus(int x, int y) {
    		System.out.println(x+y);
    	}
    	public static void mi(int x, int y) {
    		System.out.println(x-y);
    	}
    	public static void mu(int x, int y) {
    		System.out.println(x*y);
    	}
    	public static void dev(int x, int y) {
    		System.out.println(x/y);
    	}
    	public static void main(String[] args) {
    		//계산기 만들기
    		Scanner scanner = new Scanner(System.in);
    		
    		//연산자 입력받기
    		System.out.print(">> x: ");
    		int x1 = scanner.nextInt();
    		
    		System.out.print(">> y: ");
    		int y1 = scanner.nextInt();
    		
    		scanner.nextLine();
    		System.out.print(">> 연산자(+,-,*,/)를 입력하세요 : ");
    		String z = scanner.nextLine();
    		
    		
    		plus(x1, y1);
    		scanner.close();
    	}
    
    }
    

    'JAVA' 카테고리의 다른 글

    [JAVA] 조건문과 반복문  (0) 2024.09.04
    [JAVA] 상속  (0) 2024.09.04
    [이것이 자바다]문자열(String) 타입  (0) 2024.02.01
    [이것이 자바다] 배열(Array) 타입  (0) 2024.02.01
    [이것이 자바다] 객체지향 : 참조타입  (0) 2024.02.01

    댓글