Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package kr_2;
- import java.util.Scanner;
- public class FractionCalc {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- while (true) {
- String exp = sc.nextLine();
- if (exp.equalsIgnoreCase("end")) {
- break;
- }
- char op = exp.charAt(exp.indexOf(" ") + 1);
- String[] drobi = exp.split(" ([+]|[-]|[*]|[/]) ");
- Fraction d1 = new Fraction(drobi[0]);
- Fraction d2 = new Fraction(drobi[1]);
- Fraction d3 = null;
- if (op == '+') {
- d3 = d1.sum(d2);
- } else if (op == '-') {
- d3 = d1.subtract(d2);
- } else if (op == '*') {
- d3 = d1.multiply(d2);
- }
- if (op == '/') {
- d3 = d1.divide(d2);
- }
- System.out.println(d3);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement