문제 설명
세 정수 a, b, c가 입력되었을 때, 짝(even)/홀(odd)을 출력해보자.
입력
세 정수 a, b, c 가 공백을 두고 입력된다.
0 <= a, b, c <= +2147483647
출력
입력된 순서대로 짝(even)/홀(odd)을 줄을 바꿔 출력한다.
내 풀이
import java.util.Scanner;
public class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
if(a % 2 == 0) {
System.out.println("even");
} else {
System.out.println("odd");
}
if(b % 2 == 0) {
System.out.println("even");
}else {
System.out.println("odd");
}
if(c % 2 == 0) {
System.out.println("even");
} else {
System.out.println("odd");
}
}
}
문제 설명
정수 1개가 입력되었을 때, 음(minus)/양(plus)과 짝(even)/홀(odd)을 출력해보자.
입력
정수 1개가 입력된다.
-2147483648 ~ +2147483647, 단 0은 입력되지 않는다.
출력
입력된 정수에 대해 첫 줄에 minus 나 plus 를 출력하고, 두 번째 줄에 odd 나 even 을 출력한다.
내 풀이
import java.util.Scanner;
public class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
if(a % 2 == 0) {
System.out.println("even");
} else {
System.out.println("odd");
}
if(a > 0) {
System.out.println("plus");
} else {
System.out.println("minus");
}
}
}
문제 설명
점수(정수, 0 ~ 100)를 입력받아 평가를 출력해보자.
평가 기준
점수 범위 : 평가
90 ~ 100 : A
70 ~ 89 : B
40 ~ 69 : C
0 ~ 39 : D
로 평가되어야 한다.
입력
정수(0 ~ 100) 1개가 입력된다.
출력
평가 결과를 출력한다.
내 풀이
import java.util.Scanner;
public class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
if(a >= 90 && a <= 100) {
System.out.println("A");
} else if(a >= 70 && a < 90) {
System.out.println("B");
} else if(a >= 40 && a < 70) {
System.out.println("C");
} else if(a >= 0 && a < 40) {
System.out.println("D");
}
}
}
문제 설명
평가를 문자(A, B, C, D, ...)로 입력받아 내용을 다르게 출력해보자.
평가 내용
평가 : 내용
A : best!!!
B : good!!
C : run!
D : slowly~
나머지 문자들 : what?
입력
영문자 1개가 입력된다.
(A, B, C, D 등의 한 문자가 입력된다.)
출력
평가내용에 따라 다른 내용이 출력된다.
내 풀이
import java.util.Scanner;
public class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
String a = sc.next();
switch(a) {
case "A":
System.out.println("best!!!");
break;
case "B":
System.out.println("good!!");
break;
case "C":
System.out.println("run!");
break;
case "D":
System.out.println("slowly~");
break;
default :
System.out.println("what?");
}
}
}
문제 설명
월이 입력될 때 계절 이름이 출력되도록 해보자.
입력
월을 의미하는 1개의 정수가 입력된다.(1 ~ 12)
출력
계절 이름을 출력한다.
내 풀이
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
switch(a) {
case 1 :
case 2 :
System.out.println("winter");
break;
case 3 :
case 4 :
case 5 :
System.out.println("spring");
break;
case 6 :
case 7 :
case 8 :
System.out.println("summer");
break;
case 9 :
case 10 :
case 11 :
System.out.println("fall");
break;
case 12 :
System.out.println("winter");
}
}
}
'CodeUp > Java' 카테고리의 다른 글
[CodeUp_JAVA] 1076 ~ 1080 (0) | 2022.01.20 |
---|---|
[CodeUp_JAVA] 1071 ~ 1075 (0) | 2022.01.19 |
[CodeUp_JAVA] 1061 ~ 1065 (0) | 2022.01.14 |
[CodeUp_JAVA] 1056 ~ 1060 (0) | 2022.01.12 |
[CodeUp_JAVA] 1051 ~ 1055 (0) | 2022.01.10 |