알고리즘/백준
[Python/Java] 백준 1008번 - A/B
소꿍
2020. 6. 8. 16:40
https://www.acmicpc.net/problem/1008
1008번: A/B
두 정수 A와 B를 입력받은 다음, A/B를 출력하는 프로그램을 작성하시오.
www.acmicpc.net
Python
a, b = map(int, input().split())
print(a/b)
Java
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String[] s = scan.nextLine().split(" ");
double n1 = Integer.parseInt(s[0]);
double n2 = Integer.parseInt(s[1]);
double d = n1/n2;
System.out.println(d);
scan.close();
}
}
* 주의할 점: int로 값을 저장해서 나누면 1/3 을 했을 때 0이 나온다.
double로 저장해서 연산, 출력해야 소수점 이하의 값도 구할 수 있다.