java 공부하려고 남기는 게시물..
c언어로 풀고 java로 바꿔보기!!
https://www.acmicpc.net/problem/14681
14681번: 사분면 고르기
점 (x, y)의 사분면 번호(1, 2, 3, 4 중 하나)를 출력한다.
www.acmicpc.net
C
#include <stdio.h>
int main(){
int x,y;
scanf("%d %d", &x,&y);
if(x>0 && y>0)
printf("1");
if(x>0 && y<0)
printf("4");
if(x<0 && y>0)
printf("2");
if(x<0 && y<0)
printf("3");
return 0;
}
java
package javastd1;
import java.util.Scanner;
public class std1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scanner = new Scanner(System.in);
int x = scanner.nextInt();
int y = scanner.nextInt();
if(x>0 && y>0)
System.out.println("1");
if(x>0 && y<0)
System.out.println("2");
if(x<0 && y>0)
System.out.println("3");
if(x<0 && y<0)
System.out.println("4");
}
}
자바는 입력받으려면 scanner 사용
c는 scanf("%d", &d);
자바는
import java.utill.Scanner;
Scanner 이름 = new Scanner(System.in);
int x = Scanner.nextInt(); //입력받는 부분
'공부하자 > 알고리즘' 카테고리의 다른 글
[백준] 2217번 로프 C, java (0) | 2022.01.06 |
---|---|
[백준] 10162번 전자레인지 C, java (0) | 2022.01.05 |
[백준] 5585번 거스름돈 C, java (0) | 2022.01.04 |
[백준] 1026번 보물 C, java (0) | 2021.12.30 |
[백준] 11399번 ATM C, java (0) | 2021.12.30 |