メソッド

1145 ワード

方法


return;しない
メソッドでの印刷
package ch02;

public class OverloadDemo3 {

	public static void main(String[] args) {
		String s1 = "안녕", s2 = "어서와", s3 = "커피";
		int x = 10;

		str(s1, s2, s3, x);
	}

	public static void str(String s1, String s2, String s3, int x) {
		System.out.printf("친구야 %s 반갑다 %s %s %d잔 사줄께", s1, s2, s3, x);
	}
}

戻るの使用
package ch02;
    
  
public class OverloadDemo2 {

	public static void main(String[] args) {
		String s1 = "안녕", s2 = "어서와", s3 = "커피";
	//		String a1 = str(a1);
		String a = null;
		int x = 0;

		System.out.printf("친구야 %s %s %s\n", s1, s2, str(a));
		System.out.printf("친구야 %s %s %s 커피 %d잔 사줄께 ", s1, str(a), s2, str(x));
	}

	public static String str(String a) {
		String a1 = "반갑다";
		return a1;
	}

	public static int str(int x) {
		int an = 10;
		return an;
	}

}