[Baekjoon / JAVA] Baekjoon Algorithm #1008 A / B
[Baekjoon / JAVA] Baekjoon Algorithm #1008 A / B
Given two integers A and B, write a program that outputs A / B.
@RWBwritten at 2021-06-09 01:25:31
| Rank | Language Used |
|---|---|
🖼️ JAVA |
| Time Limit | Memory Limit |
|---|---|
| 2 sec | 128MB |
Given two integers and , write a program that outputs .
The first line gives and .
Print on the first line. It's correct as long as the absolute or relative error between the actual answer and the output value is at most .
- Input
TC
1 3
- Output
TC
0.33333333333333333333333333333333
Allowing an error of up to doesn't necessarily mean you must print exactly to the 9th decimal place.
- Input
TC
4 5
- Output
TC
0.8
An arithmetic problem following Baekjoon 1000 A + B and Baekjoon 1001 A - B. Hard to get wrong.
For JAVA, just be careful that when you divide with int, only the integer portion is returned, so you must declare the values as a floating-point type such as double before dividing.
JAVA
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; /** * Baekjoon problem #1008 algorithm class * * @author RWB * @see <a href="https://blog.itcode.dev/posts/2021/06/09/a1008">1008 solution</a> * @since 2021.06.09 Tue 10:23:59 */ public class Main { /** * Main function * * @param args: [String[]] arguments * * @throws IOException data input/output exception */ public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String[] line = reader.readLine().split(" "); double a = Double.parseDouble(line[0]); double b = Double.parseDouble(line[1]); System.out.println(a / b); reader.close(); } }
- Math
- Implementation
- Arithmetic
# Baekjoon# Algorithm# JAVA(Java)# Arithmetic# BRONZE# BRONZE IV
