(adsbygoogle = window.adsbygoogle || []).push({ google_ad_client: "ca-pub-8242763509535969", enable_page_level_ads: true }); 'code/JAVA' 카테고리의 글 목록 (2 Page) :: 깜냥깜냥
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
34
35
36
37
38
39
40
41
42
43
44
import java.util.Scanner;
 
public class HelloWorld{
 
    public static void main(String[] args) { // 메소드
 
        int a, b;
        String op;
        char yn;
 
        do {
            Scanner sc = new Scanner(System.in);
 
            System.out.print("First Number Input:"); // 첫번째 숫자입력
            a = sc.nextInt();
 
            System.out.print("Operation Input:"); // 연산기호 입력
            op = sc.next();
 
            System.out.print("Two Number Input:");// 두번째 숫자입력
            b = sc.nextInt();
 
            switch (op) {
            case "+":
                System.out.println(a + " " + op + " " + b + " " + "=" + " " + (a + b));
                break;// a+" "+op+" "+b+" "+"="+" "+(a+b)-> a+b=(a+b)
            case "-":
                System.out.println(a + " " + op + " " + b + " " + "=" + " " + (a - b));
                break;
            case "*":
                System.out.println(a + " " + op + " " + b + " " + "=" + " " + (a * b));
                break;
            case "/":
                System.out.println(a + " " + op + " " + b + " " + "=" + " " + ((float) a / (float) b));
                break// int->float형 변환
            default:
                System.out.println("Error!");
            }
 
            System.out.print("continue? Y or N:");
            yn = sc.next().charAt(0);
        } while (yn == 'y' || yn == 'Y');// y,Y면 다시.
    }
}


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
34
import java.util.Scanner;
 
public class StudentScore {
    public static void main(String[] ar) {
        Scanner sc = new Scanner(System.in);
 
        int num;
        System.out.print("Number Input: ");
        num = sc.nextInt();
        String[] name = new String[num];
        int[][] score = new int[num][4];
        double[] avg = new double[num];
 
        for (int i = 0; i < score.length; i++) {
            System.out.print("Name Input: ");
            name[i] = sc.next();
            for (int j = 0; j < score[i].length - 1; j++) {
                System.out.print("Score Input: ");
                score[i][j] = sc.nextInt();
                score[i][3] += score[i][j];
            }
            avg[i] = score[i][3] / 3;
        }
        System.out.println("Name""\t"+"Kor"+"\t"+"Eng"+"\t"+"Math"+"\t"+"Total"+"\t"+"Avg");
        for (int i = 0; i < score.length; i++) {
            System.out.print(name[i] + "\t");
            for (int j = 0; j < score[i].length; j++) {
                System.out.print(score[i][j] + "\t");
            }
            System.out.println(avg[i]);
        }
    }
}
 


+ Recent posts