14681번: 사분면 고르기
점 (x, y)의 사분면 번호(1, 2, 3, 4 중 하나)를 출력한다.
www.acmicpc.net
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
int x;
int y;
Scanner sc = new Scanner(System.in);
x = sc.nextInt();
y = sc.nextInt();
if(x > 0 && y > 0){
System.out.println(1);
}
else if(x < 0 && y > 0){
System.out.println(2);
}
else if(x < 0 && y < 0){
System.out.println(3);
}
else if(x > 0 && y < 0){
System.out.println(4);
}
}
}
2525번: 오븐 시계
첫째 줄에 종료되는 시각의 시와 분을 공백을 사이에 두고 출력한다. (단, 시는 0부터 23까지의 정수, 분은 0부터 59까지의 정수이다. 디지털 시계는 23시 59분에서 1분이 지나면 0시 0분이 된다.)
www.acmicpc.net
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
int h;
int m;
int m1;
Scanner sc = new Scanner(System.in);
h = sc.nextInt();
m = sc.nextInt();
m1 = sc.nextInt();
m1 += m;
while(m1 >=60){
if (m1 >= 60){
m1 -= 60;
h+=1;
}
}
if (h >= 24){
h -=24;
}
System.out.print(h+" "+m1);
}
}
2480번: 주사위 세개
1에서부터 6까지의 눈을 가진 3개의 주사위를 던져서 다음과 같은 규칙에 따라 상금을 받는 게임이 있다. 같은 눈이 3개가 나오면 10,000원+(같은 눈)×1,000원의 상금을 받게 된다. 같은 눈이 2개
www.acmicpc.net
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
int n1;
int n2;
int n3;
Scanner sc = new Scanner(System.in);
n1 = sc.nextInt();
n2 = sc.nextInt();
n3 = sc.nextInt();
if (n1==n2 && n1==n3){
System.out.println(10000+(n1*1000));
}
else if(n1==n2){
System.out.println(1000+(n1*100));
}
else if(n2==n3){
System.out.println(1000+(n2*100));
}
else if(n1==n3){
System.out.println(1000+(n3*100));
}
else{
if (n1>n2){
if(n1>n3){
System.out.println(n1*100);
}
else{
System.out.println(n3*100);
}
}
else{
if(n2>n3){
System.out.println(n2*100);
}
else{
System.out.println(n3*100);
}
}
}
}
}
2739번: 구구단
N을 입력받은 뒤, 구구단 N단을 출력하는 프로그램을 작성하시오. 출력 형식에 맞춰서 출력하면 된다.
www.acmicpc.net
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
int n;
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
for(int i=1; i<=9; i++){
System.out.println(n+" * "+i+" = "+(n*i));
}
}
}
10871번: X보다 작은 수 (acmicpc.net)
10871번: X보다 작은 수
첫째 줄에 N과 X가 주어진다. (1 ≤ N, X ≤ 10,000) 둘째 줄에 수열 A를 이루는 정수 N개가 주어진다. 주어지는 정수는 모두 1보다 크거나 같고, 10,000보다 작거나 같은 정수이다.
www.acmicpc.net
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
int n;
int x;
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
x = sc.nextInt();
for(int i=0;i<n;i++){
int nlist = sc.nextInt();
if (nlist < x){
System.out.print(nlist+" ");
}
}
}
}
'2022 > JAVA' 카테고리의 다른 글
ep 04-2. 상속과 다형성 (0) | 2022.11.27 |
---|---|
ep 04-1. 배열과 ArrayList (0) | 2022.11.27 |
ep 03-3. 클래스와 객체2 (0) | 2022.11.20 |
ep 03-2. 클래스와 객체1 (0) | 2022.11.20 |
ep 03-1. 제어 흐름 이해하기 (0) | 2022.11.20 |