[코드업 기초 100제] [기초 - 조건/선택 & 반복 실행 구조] 코드업 1065 ~ 1077 자바 풀이

2022. 2. 15. 23:10코딩테스트/코드업

728x90
반응형

문제 출처


https://github.com/haessae0/MCTP

 

1065. 정수 3개 입력받아 짝수만 출력하기

import java.io.*;

public class codeup1065 {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String array[] = br.readLine().split(" ");

    int a = Integer.parseInt(array[0]);
    int b = Integer.parseInt(array[1]);
    int c = Integer.parseInt(array[2]);

    int data[] = { a, b, c };

    for (int i = 0; i < data.length; i++) {
      if (data[i] % 2 == 0) {
        System.out.println(data[i]);
      }
    }

  }

}

 

1066. 정수 3개 입력받아 짝/홀 출력하기

import java.io.*;

public class codeup1066 {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String array[] = br.readLine().split(" ");

    int a = Integer.parseInt(array[0]);
    int b = Integer.parseInt(array[1]);
    int c = Integer.parseInt(array[2]);

    int data[] = { a, b, c };

    for (int i = 0; i < data.length; i++) {
      if (data[i] % 2 == 0) {
        System.out.println("even");
      } else {
        System.out.println("odd");
      }
    }
  }

}

 

1067. 정수 1개 입력받아 분석하기

import java.io.*;

public class codeup1067 {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int data = Integer.parseInt(br.readLine());

    if (data > 0) {
      System.out.println("plus");
      if (data % 2 == 0) {
        System.out.println("even");
      } else {
        System.out.println("odd");
      }
    } else {
      System.out.println("minus");
      if (data % 2 == 0) {
        System.out.println("even");
      } else {
        System.out.println("odd");
      }
    }
  }

}

 

1068. 정수 1개 입력받아 평가 출력하기

import java.io.*;

public class codeup1068 {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int data = Integer.parseInt(br.readLine());

    if (90 <= data && data <= 100) {
      System.out.println("A");
    } else if (70 <= data && data <= 89) {
      System.out.println("B");
    } else if (40 <= data && data <= 69) {
      System.out.println("C");
    } else if (0 <= data && data <= 399) {
      System.out.println("D");
    }
  }
}

 

1069. 평가 입력받아 다르게 출력하기

import java.io.*;

public class codeup1069 {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    char data = br.readLine().charAt(0);

    switch (data) {
      case 'A':
        System.out.print("best!!!");
        break;
      case 'B':
        System.out.print("good!!");
        break;
      case 'C':
        System.out.print("run!");
        break;
      case 'D':
        System.out.print("slowly~");
        break;
      default:
        System.out.print("what?");
        break;
    }
  }

}

 

1070. 월 입력받아 계절 출력하기

import java.io.*;

public class codeup1070 {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int data = Integer.parseInt(br.readLine());

    switch (data) {
      case 12:
      case 1:
      case 2:
        System.out.print("winter");
        break;
      case 3:
      case 4:
      case 5:
        System.out.print("spring");
        break;
      case 6:
      case 7:
      case 8:
        System.out.print("summer");
        break;
      case 9:
      case 10:
      case 11:
        System.out.print("fall");
        break;
    }
  }

}

 

1071. 0 입력될 때까지 무한 출력하기 1

import java.util.Scanner;

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

    while (true) {
      int data = sc.nextInt();

      if (data != 0) {
        System.out.println(data);
      } else {
        break;
      }
    }
  }

}

 

1072. 정수 입력받아 계속 출력하기

import java.util.Scanner;

public class codeup1072 {
  public static void main(String[] args) throws Exception {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int array[] = new int[a];

    for (int i = 0; i < a; i++) {
      array[i] = sc.nextInt();
      System.out.println(array[i]);
    }
  }

}

 

1073. 0 입력될 때까지 무한 출력하기 2

import java.util.Scanner;

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

    while (true) {
      int data = sc.nextInt();

      if (data != 0) {
        System.out.println(data);
      } else {
        break;
      }
    }
  }

}

 

1074. 정수 1개 입력받아 카운트다운 출력하기 1

import java.io.*;

public class codeup1074 {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int data = Integer.parseInt(br.readLine());

    while (true) {
      System.out.println(data);
      data--;
      if (data == 0)
        break;
    }
  }

}

 

1075. 정수 1개 입력받아 카운트다운 출력하기 2

import java.io.*;

public class codeup1075 {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int data = Integer.parseInt(br.readLine());

    while (true) {
      data--;
      System.out.println(data);

      if (data == 0)
        break;

    }
  }

}

 

1076. 문자 1개 입력받아 알파벳 출력하기

import java.io.*;

public class codeup1076 {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    char data = br.readLine().charAt(0);

    char a = 'a';

    while (a <= data) {
      System.out.print(a + " ");
      a++;
    }
  }

}

 

1077. 정수 1개 입력받아 그 수까지 출력하기

import java.io.*;

public class codeup1077 {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int data = Integer.parseInt(br.readLine());

    for (int i = 0; i <= data; i++) {
      System.out.println(i);
    }
  }

}

 

728x90
반응형