Yatta!

sunny1022.egloos.com

포토로그


최근 포토로그


1장) 크기비교 자료구조&알고리즘 by JAVA



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
package AD;
import java.util.Scanner;
public class test {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        
        System.out.println("세 정수의 최댓값");
        System.out.print("a:"); int a =std.nextInt();
        
        System.out.println("세 정수의 최댓값");
        System.out.print("b:"); int b =std.nextInt();
        System.out.println("세 정수의 최댓값");
        System.out.print("c:"); int c =std.nextInt();
        
        int max=a;
        
        if(b>max)
            max = b; //b가 max보다 크면 대체
        if(c>max)
            max = c; //c가 max보다 크면 대체
        
        
        System.out.print("max: " + max);
    }
}
cs


[가벼운 응용]
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
31
32
33
package AD;
import java.util.Scanner;
public class test {
    
    static int min(int a, int b, int c, int d) {
        int m=a;
        
        if(m>b)
            m=b;
        if(m>c)
            m=c;
        if(m>d)
            m=d;
        
        return m;
    }
    
    
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        
        System.out.println("세 정수의 최소값");
        System.out.print("a:"); int a =std.nextInt();
        System.out.print("b:"); int b =std.nextInt();
        System.out.print("c:"); int c =std.nextInt();
        System.out.print("d:"); int d =std.nextInt();
    
        
        
        System.out.print("min: " + min(a,b,c,d));
    }
 
}
cs