π© λ©μλλ?
νΉμ μμ μ μννλ μΌλ ¨μ λ¬Έμ₯λ€μ νλλ‘ λ¬Άμ κ²μ΄λ€.
β λ©μλλ₯Ό μ¬μ©νλ μ΄μ
- λμ μ¬μ¬μ©μ± : νλ² λ§λ€μ΄ λμ λ©μλλ λͺ λ²μ΄κ³ νΈμΆν μ μλ€.
- μ€λ³΅λ μ½λμ μ κ±° : λ°λ³΅λλ λ¬Έμ₯μ λ¬Άμ΄μ λ©μλλ‘ μμ±νλ©΄, λ©μλλ₯Ό νΈμΆνλ λ¬Έμ₯μΌλ‘ λ체ν μ μλ€.
- νλ‘κ·Έλ¨μ ꡬ쑰ν : λ©μλλ₯Ό μ¬μ©ν΄ mainμμ μ 체 νλ¦μ΄ νλμ λ€μ΄μ€κ² ꡬ쑰ν κ°λ₯νλ€.
β λ©μλμ μ μΈκ³Ό ꡬν
public static λ°νκ°νμ ν¨μλͺ
(μΈμνμ)//λ©μλ μ μΈλΆ
public static int num(int a, int b){ //μμ
return λ°νκ°;
}
num(3,4); //λ©μλ ꡬνλ°©λ²
λ°ννλκ²μ κ·Έ ν¨μλ₯Ό ν΅ν΄ 무μμ΄ λ¨λμ§? λ¨κ²¨μ§λκ²μ νλ€.
public class Program2 {
//λ‘λλ²νΈ μ μ₯νκΈ°
public static int[][] creatLottos(){
int[][] lottos={{1,2,3,4,5,6},{7,8,9,10,11,12},{13,14,15,16,17,18}};
return lottos;
}
//λ‘λ μΆλ ₯
public static void printLottos(int[][] lottos){
for(int i=0;i<3;i++) {
for (int j = 0; j < 6; j++)
System.out.printf("%4d, ",lottos[i][j]);
System.out.println();
}
}
//λ‘λ μ μ₯μ λ°κΏμ£ΌκΈ°
public static void swapLottos(int[][] lottos,int i,int j){
int[] temp = lottos[i];
lottos[i]=lottos[j];
lottos[j]=temp;
}
public static void main(String[] args) {
int[][] lottos = creatLottos();//λ‘λλ²νΈ μμ± ν lottosμ μ μ₯ν΄μ£ΌκΈ°
//λ‘λ μΆλ ₯
printLottos(lottos);
System.out.println("\n-----------첫λ²μ§Έμ μΈλ²μ§Έ λ°κΎΈκΈ°-----------\n");
//λ‘λ μ μ₯μ λ°κΏμ£ΌκΈ°
swapLottos(lottos,0,2);//κ°λ°κΎΈκΈ°
//λ‘λ μΆλ ₯
printLottos(lottos);
}
}
public class BasicProgram2 {
static int sum(int n) {
int total = (n * (n + 1)) / 2;
return total;
}
static int power(int x) {
return ((x + 3) * (x + 3) + x / 3 * (x - 2) + 5);
}
public static void main(String[] args) {
//int result = 1+2+3+4+5+6+7+8+9+10~n;
int result = sum(11);
System.out.printf("result : %d\n", result);
//(x+3)*(x+3)+ x/3*(x-2)+5
int result2 = power(7) + 3 + power(7) - power(3);
System.out.printf("result : %d\n", result2);
int a1 = f1();
int a2 = f2(20, 30);
f3(33);
f4(9);
// int[] lotto = new int[3];
// print(3,5.3f,lotto);
char[][] names = new char[3][10];
double cnt = print(true, 4.0, names);
}
static double print(boolean a, double b, char[][] c) {
return 2.2;
}
//print(2,3.0f,'a') ν¨μλ‘ λ§λ€μ΄λ³΄μ!
// static void print(int i, float f,int[] a){
// System.out.printf("μΆλ ₯ κ° : %d %.2f %c\n",i,f,a[0]);
// }
private static void f4(int i) {
System.out.printf("μΆλ ₯ κ° : %d\n", i);
}
private static void f3(int i) {
}
private static int f2(int i, int i1) {
return 0;
}
private static int f1() {
return 0;
}
}
'IT > JAVA' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[Java] 컬λ μ (Collection) ? (1) | 2023.07.09 |
---|---|
[Java] ν¨μ μ€λ²λ‘λ(overload) (1) | 2023.07.04 |
[JAVA] λ³μμ μμλ³μ (0) | 2023.06.26 |
[Java] λ°°μ΄(Array) (0) | 2023.06.21 |
[Java]λΉνΈ μ°μ°μλ‘ λ°μ΄ν°κ° μΆμΆνκΈ° (0) | 2023.06.12 |