221004 코드업

Jeonghyeon Kim·2022년 10월 4일
0

화폐

import java.util.Scanner;

public class PayTest {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int pay;
        int[] currencyType = {50000, 10000, 5000, 1000, 500, 100, 50, 10};

        System.out.println("금액을 넣으세요: >>");

        pay = sc.nextInt();

        for (int i = 0; i < currencyType.length; i++) {
            System.out.println(currencyType[i] + "원?" + pay / currencyType[i] + "개");
            pay = pay - ((pay / currencyType[i]) * currencyType[i]); //비효율의 끝을 달리는구먼..
        }

    }
}
public class PayTest2 {

    public static void main(String[] args) {

        int curr50000 = 50000;
        int curr10000 = 10000;
        int curr5000 = 5000;
        int curr1000 = 1000;
        int curr500 = 500;
        int curr100 = 100;
        int curr50 = 50;
        int curr10 = 10;

        int refund = 25400;

        System.out.printf("5만원권 %d장 나머지:%d\n", refund / curr50000, refund % 50000);
        System.out.printf("1만원권 %d장 나머지:%d\n", refund / curr10000, refund % 10000);
        //refund = refund - ((refund/curr1000)*10000);//5000원권은 한 장만 나오게 하고 싶다. 왜냐면 위에서 만원권 2장 나왔기 때문이다.
        refund = refund % 10000; //이것도 가능. modulo라고 한다. (나머지 mod %)

        System.out.printf("5천원권 %d장 나머지:%d\n", refund / curr5000, refund % 5000);
        refund = refund % 5000;

        System.out.printf("1천원권 %d장 나머지:%d\n", refund / curr1000, refund % 1000);
        refund = refund % 1000;

        System.out.printf("5백원권 %d장 나머지:%d\n", refund / curr500, refund % 500);
        refund = refund % 500;

        System.out.printf("1백원권 %d장 나머지:%d\n", refund / curr100, refund % 100);
        refund = refund % 100;

        System.out.printf("5십원권 %d장 나머지:%d\n", refund / curr50, refund % 50);
        System.out.printf("1십원권 %d장", refund / curr10);

    }
}

❓ 용준이와 봉찬이는 공기 놀이로 내기를 하였다.
만약 홀수개의 돌을 쥐게 되면 용준이가 이기게 되고, 짝수개의 돌을 쥐게 되면 봉찬이가 이기는 것으로 룰을 정하였다.
어떤 자연수가 입력되면 홀수이면 "odd"을 출력하고, 짝수이면 "even"을 출력하시오.

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int num = sc.nextInt();

        if(num % 2 == 0){
            System.out.println("even");
        }else {
            System.out.println("odd");
        }
    }
}

코드업1161

❓ 정수 두개가 입력으로 들어온다. 만약 첫번째 정수가 홀수이면 "홀수"를 출력하고, 짝수이면 "짝수"를 출력한 후 "+"를 출력한다. 그리고 두번째 정수가 홀수이면 "홀수"를 출력하고, 짝수이면 "짝수"를 출력한 후 "="을 출력하고 결과로 나오는 값이 홀수인지 짝수인지 출력한다. 예를들어, 5 7 이 입력되면 "홀수+홀수=짝수"가 출력된다. 5 6 이 입력되면 "홀수+짝수=홀수"가 출력된다.
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int num = sc.nextInt();
        int num2 = sc.nextInt();

        if (num % 2 != 0) {
            System.out.print("홀수");
        } else {
            System.out.print("짝수");
        }

        System.out.print("+");

        if (num2 % 2 != 0) {
            System.out.print("홀수");
        } else {
            System.out.print("짝수");
        }
        System.out.print("=");

        if ((num + num2) % 2 == 0) {
            System.out.print("짝수");
        }else {
            System.out.print("홀수");
        }
    }
}

코드업 1001~1011

import java.util.Scanner;

public class Sol1004 {
    public static void main(String[] args) {
        System.out.printf("Hello", args);
    }
}

 class Main2 {
    public static void main(String[] args) {
        System.out.println("Hello World");
    }
}

class Main3 {
    public static void main(String[] args) {
        System.out.printf("Hello\nWorld");
    }
}

class Main4 {
    public static void main(String[] args) {
        System.out.println("\'Hello\'");
    }
}

class Main5 {
    public static void main(String[] args) {
        System.out.println("\"Hello World\"");
    }
}

class Main6 {
    public static void main(String[] args) {
        System.out.println("\"!@#$%^&*()\"");
    }
}

class Main7 {
    public static void main(String[] args) {
        System.out.println("\"C:\\Download\\hello.cpp\"");
    }
}

class Main8 {
    public static void main(String[] args) {
        //https://unicode-table.com/en/blocks/box-drawing/

        System.out.printf("\u250C\u252C\u2510\n");
        System.out.printf("\u251C\u253C\u2524\n");
        System.out.printf("\u2514\u2534\u2518\n");
    }
}

class Main9 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int num = sc.nextInt();

        System.out.println(num);
    }
}

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        char ch = sc.next().charAt(0);
        //char타입은 scanner로 입력받을 수 없다.
        //하지만 charat이 있음.
        //String으로 저장된 문자열 중에서 한 글자만 선택해서 CHAr타입으로 변환해줌

        System.out.println(ch);
    }
}
profile
hello world

0개의 댓글