๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
TIL

01/02(ํ™”) ๋‚ด์ผ๋ฐฐ์›€์บ ํ”„ Java 7์ผ์ฐจ TIL - ์—ฐ์‚ฐ์ž, ์กฐ๊ฑด๋ฌธ, ๋ฐ˜๋ณต๋ฌธ

by ๊ฐ์ž๊ฐœ๋ฐœ๊พผ 2024. 1. 3.

 

๐Ÿ“–  ์˜ค๋Š˜์˜ ํ•™์Šต ํ‚ค์›Œ๋“œ

  • ์—ฐ์‚ฐ์ž
  • ์กฐ๊ฑด๋ฌธ
  • ๋ฐ˜๋ณต๋ฌธ

 

๐Ÿฅ”  ์—ฐ์‚ฐ์ž์˜ ์ข…๋ฅ˜

  • ์‚ฐ์ˆ ์—ฐ์‚ฐ์ž : +, -, *, /, %, <<, >>
  • ๋น„๊ต์—ฐ์‚ฐ์ž : >, <, >=, <=, ==, !=
  • ๋…ผ๋ฆฌ์—ฐ์‚ฐ์ž : && (AND), || (OR), ! (NOT)
  • ๋Œ€์ž…์—ฐ์‚ฐ์ž : =, ++, --
  • ์‚ผํ•ญ์—ฐ์‚ฐ์ž : ์กฐ๊ฑด ? ์ฐธ : ๊ฑฐ์ง“

๐Ÿฅ”  ์กฐ๊ฑด๋ฌธ์œผ๋กœ ๊ฐ€์œ„๋ฐ”์œ„๋ณด ๋งŒ๋“ค๊ธฐ

package week02;

import java.util.Objects;
import java.util.Scanner;

public class W01 {

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

        System.out.println("A์ž…๋ ฅ :");
        String aHand = scanner.nextLine();

        System.out.println("B์ž…๋ ฅ :");
        String bHand = scanner.nextLine();

        if (Objects.equals(aHand, "๊ฐ€์œ„")) {
            if (Objects.equals(bHand, "๊ฐ€์œ„")) {
                System.out.println("A์™€ B๋Š” ๋น„๊ฒผ์Šต๋‹ˆ๋‹ค.");
            } else if (Objects.equals(bHand, "๋ฐ”์œ„")) {
                System.out.println("B๊ฐ€ ์ด๊ฒผ์Šต๋‹ˆ๋‹ค.");
            } else if (Objects.equals(bHand, "๋ณด")) {
                System.out.println("A๊ฐ€ ์ด๊ฒผ์Šต๋‹ˆ๋‹ค.");
            } else {
                System.out.println("B๊ฐ€ ์ด์ƒํ•œ ๊ฐ’์„ ์ž…๋ ฅํ–ˆ์Šต๋‹ˆ๋‹ค.");
            }

        } else if (Objects.equals(aHand, "๋ฐ”์œ„")) {
            if (Objects.equals(bHand, "๊ฐ€์œ„")) {
                System.out.println("A๊ฐ€ ์ด๊ฒผ์Šต๋‹ˆ๋‹ค.");
            } else if (Objects.equals(bHand, "๋ฐ”์œ„")) {
                System.out.println("A์™€ B๋Š” ๋น„๊ฒผ์Šต๋‹ˆ๋‹ค.");
            } else if (Objects.equals(bHand, "๋ณด")) {
                System.out.println("B๊ฐ€ ์ด๊ฒผ์Šต๋‹ˆ๋‹ค.");
            } else {
                System.out.println("B๊ฐ€ ์ด์ƒํ•œ ๊ฐ’์„ ์ž…๋ ฅํ–ˆ์Šต๋‹ˆ๋‹ค.");
            }

        } else if (Objects.equals(aHand, "๋ณด")) {
            if (Objects.equals(bHand, "๊ฐ€์œ„")) {
                System.out.println("B๊ฐ€ ์ด๊ฒผ์Šต๋‹ˆ๋‹ค.");
            } else if (Objects.equals(bHand, "๋ฐ”์œ„")) {
                System.out.println("A๊ฐ€ ์ด๊ฒผ์Šต๋‹ˆ๋‹ค.");
            } else if (Objects.equals(bHand, "๋ณด")) {
                System.out.println("A์™€ B๋Š” ๋น„๊ฒผ์Šต๋‹ˆ๋‹ค.");
            } else {
                System.out.println("B๊ฐ€ ์ด์ƒํ•œ ๊ฐ’์„ ์ž…๋ ฅํ–ˆ์Šต๋‹ˆ๋‹ค.");
            }

        } else {
            System.out.println("A๊ฐ€ ์ด์ƒํ•œ ๊ฐ’์„ ์ž…๋ ฅํ–ˆ์Šต๋‹ˆ๋‹ค.");
        }
    }
}

 

 

๐Ÿฅ”  ๋ฐ˜๋ณต๋ฌธ์œผ๋กœ ๊ตฌ๊ตฌ๋‹จ ๋งŒ๋“ค๊ธฐ

package week02;

import java.util.Scanner;

public class W05 {

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

        System.out.print("๊ตฌ๊ตฌ๋‹จ์˜ ์ˆ˜๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”: ");
        int num = scanner.nextInt();

        for (int i = num; i <= num; i++) {
            for (int j = 1; j <= 9; j++) {
                System.out.println(i + " x " + j + " = " + i * j);
            }
        } // ์—ฌ๊ธฐ๊นŒ์ง€๋Š” ์ž…๋ ฅํ•œ ๊ตฌ๊ตฌ๋‹จ์„ ์ถœ๋ ฅํ•˜๊ธฐ ์•„๋ž˜๋Š” ์ž…๋ ฅํ•œ ๊ตฌ๊ตฌ๋‹จ์„ ์ œ์™ธํ•œ ๊ตฌ๊ตฌ๋‹จ ์ถœ๋ ฅ

//        System.out.print("๊ฑด๋„ˆ๋›ธ ๊ตฌ๊ตฌ๋‹จ์„ ์ž…๋ ฅํ•˜์„ธ์š”: ");
//        int passNum = scanner.nextInt();
//
//        for (int i = 2; i <= 9; i++) {
//            if (i == passNum) {
//                continue;
//            }
//            for (int j = 1; j <= 9; j++) {
//                System.out.println(i + " x " + j + " = " + i * j);
//            }
//        }
    }
}

 

 

๐Ÿ“š  ์˜ค๋Š˜์˜ ํšŒ๊ณ 

์˜ค๋Š˜์€ ์ „์ฒด์ ์œผ๋กœ ๊ฐ•์˜๋ฅผ ์—ด์‹ฌํžˆ ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค.

ํ‰์†Œ์— ์ด๊ฒƒ์ €๊ฒƒ ํ•˜๋ฉด์„œ ๋“ฃ๋‹ค๊ฐ€ ํ•œ ๊ฐœ๋งŒ ์—ด์‹ฌํžˆ ํ•˜๋‹ˆ๊นŒ ์ง‘์ค‘์ด ๋” ์ž˜ ๋˜์—ˆ๋˜ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

๋‚ด์ผ๋„ ์—ด์‹ฌํžˆ ํ•œ ๋‹จ๊ณ„ ์„ฑ์žฅํ•œ ๊ฐ์ž๊ฐœ๋ฐœ๊พผ์ด ๋˜๊ฒ ์Šต๋‹ˆ๋‹ค.