반응형
출처
백준온라인저지 1008번 문제
https://www.acmicpc.net/problem/1008
문제
두 정수 A와 B를 입력받은 다음, A/B 를 출력하는 프로그램을 작성하시오.
입력
첫째 줄에 A와 B가 주어진다. (0<A, B<10)
출력
첫째 줄에 A/B를 출력한다. 절대/상대 오차는 10^-9 까지 허용한다.
예제 입력1
1
|
1 3
|
예제 출력1
1
|
0.33333333333333333333333333333333
|
코드 (실패)
1
2
3
4
5
6
7
8
9
10
11
12
|
public class Main {
public static void main (String [] args){
Scanner sc = new Scanner (System.in);
int a,b;
a=sc.nextInt();
b=sc.nextInt();
System.out.println(a/b);
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4f; text-decoration:none">Colored by Color Scripter
|
코드 (성공)
1
2
3
4
5
6
7
8
9
10
11
12
|
public class Main {
public static void main (String [] args){
Scanner sc = new Scanner (System.in);
double a,b;
a=sc.nextDouble();
b=sc.nextDouble();
System.out.println(a/b);
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4f; text-decoration:none">Colored by Color Scripterㅇ
|
출력은 소수점 9자리까지 표시해야한다.
그러므로 출력되는 값은 실수여야 해서 Scanner로 받는 인수를 Double로 설정하였다.
반응형