From 4d3b95ea1f731581163878c3d6cb21dc60c992b7 Mon Sep 17 00:00:00 2001 From: subhang-IITD <137153239+subhang-IITD@users.noreply.github.com> Date: Sat, 7 Dec 2024 12:51:32 +0530 Subject: [PATCH 1/2] Update fractions.java --- fractions.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fractions.java b/fractions.java index 23022c7..244969a 100644 --- a/fractions.java +++ b/fractions.java @@ -10,3 +10,9 @@ void reducedFrac(pair p){ p.x /=g; p.y /=g; } +pair p1 = new pair(3, 4); // Represents the fraction 3/4 +pair p2 = new pair(6, 8); // Represents the fraction 6/8 +int result = fracCompare(p1, p2); // result will be 0 (because 3/4 == 6/8) + +pair p = new pair(6, 8); // Represents the fraction 6/8 +reducedFrac(p); // Now p is reduced to 3/4 From 394e2416e5adcc4b41f67d94e65e447bfa5d8e26 Mon Sep 17 00:00:00 2001 From: subhang-IITD <137153239+subhang-IITD@users.noreply.github.com> Date: Sat, 7 Dec 2024 12:53:34 +0530 Subject: [PATCH 2/2] Update fractions.java --- fractions.java | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/fractions.java b/fractions.java index 244969a..6c67635 100644 --- a/fractions.java +++ b/fractions.java @@ -16,3 +16,29 @@ void reducedFrac(pair p){ pair p = new pair(6, 8); // Represents the fraction 6/8 reducedFrac(p); // Now p is reduced to 3/4 + +class pair { + long x, y; // 'x' is the numerator and 'y' is the denominator + + // Constructor to initialize the pair + public pair(long x, long y) { + this.x = x; + this.y = y; + } + + // Optional: You can also override toString() for easy printing + @Override + public String toString() { + return x + "/" + y; // Return the fraction in string form + } +} + +public class Main { + public static void main(String[] args) { + // Create a pair representing the fraction 3/4 + pair p1 = new pair(3, 4); + System.out.println("Fraction: " + p1); // Output: Fraction: 3/4 + } +} + +