This question requires programming to compare the two rational numbers.
Input Format:
Input two rational numbers in the form of scores in a row in the format of "A1/B1 A2/B2". The numerator and denominator are all positive integers in the Integer Range.
Output Format:
Output two rational numbers in a row in the format of "A1/B1 link character A2/B2. ">" Indicates "greater than", "<" indicates "less than", and "=" indicates "equal ".
Input Example 1:
1/2 3/4
Output Example 1:
1/2 < 3/4
Input Example 2:
6/8 3/4
Output Example 2:
6/8 = 3/4
import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner cin = new Scanner(System.in);String str = cin.nextLine();int[] a = new int[4];int temp = 0;int j = 0;for (int i = 0; i < str.length(); i++) {if (str.charAt(i) >= '0' && str.charAt(i) <= '9') {temp = temp * 10 + str.charAt(i) - '0';} else {j++;temp = 0;}a[j] = temp;}double d1 = ((double) a[0]) / a[1];double d2 = ((double) a[2]) / a[3];if (d1 > d2) {System.out.printf("%d/%d > %d/%d", a[0], a[1], a[2], a[3]);} else if (d1 < d2) {System.out.printf("%d/%d < %d/%d", a[0], a[1], a[2], a[3]);} else {System.out.printf("%d/%d = %d/%d", a[0], a[1], a[2], a[3]);}}}