RationalOperations

.java

School

Rutgers University *

*We aren’t endorsed by this school

Course

CS 314

Subject

Computer Science

Date

Oct 30, 2023

Type

java

Pages

2

Uploaded by devanshi04

package programmingProjects; import java.util.Scanner; public class RationalOperations { static int n1, d1, n2, d2; static Scanner scn = new Scanner(System.in); public static void main(String[] args) { getInput(); menu(); } public static void menu(){ int choice; pln("Select the operation that you would like to perform"); pln("1: Addition\n2: Subtraction\n3: Multiplication\n4: Division"); choice = scn.nextInt(); if(choice==1){ addition(); } } public static void addition(){ int nn = n1*d2+n2*d1; int nd = d1*d2; int gcf = gcf(nn, nd); pln("Sum is: " + nn/gcf+"/"+nd/gcf); } public static void getInput(){ pln("Input first rational number"); pln("Numerator: "); n1 = scn.nextInt(); pln("Denomenator: "); d1 = scn.nextInt(); pln("Input second rational number"); pln("Numerator: "); n2 = scn.nextInt(); pln("Denomenator: "); d2 = scn.nextInt(); pln("Rational 1: " + n1+"/"+d1); pln("Rational 2: " + n2+"/"+d2); pln("--------------------------"); } public static void pln(String s){ System.out.println(s); } public static int gcf(int a, int b){ for(int i = Math.min(a, b); i>=1; i--){ if(a%i==0 && b%i==0){ return i; } } return 1; }
}
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help

Browse Popular Homework Q&A

Q: Rewrite the following radical with a rational exponent. ... 5x [(5) - (Simplify your answer. Use…
Q: You are getting a $100,000 mortgage and paying 2 points.  What is the effective annual yield (in…
Q: If the price elasticity of demand for football tickets is estimated to be 4.5, then a 10 percent…
Q: Convert the complex number z = 3 cos -3 (con (16) +isin (¹6) 2= + help (numbers) Note: You can earn…
Q: State the excluded values for this rational expression  x^2+2x-2 / x^3+5x^2+6x
Q: Which of the following Lewis structures for molecules has the correct polarity indicated for its…
Q: What causes costs of production to vary with output in the short run? What generally causes costs…
Q: As in World War I, Americans at home during the Second World War worked to focus the public’s…
Q: A bacterial toxin causes paralysis, and upon structural elucidation was found to be a protein with…
Q: Explain how breast milk is formed in the mammary glands and the physiology of breast milk
Q: and and connections Random error, genetics Inhibitory synapses, dopamine Frequency, recency O…
Q: A crate with a mass of 30 kg rests on a floor. On top of the crate stands a 45-kg girl. What is the…
Q: Table 2: Two Lenses fi(cm) P₁(cm) q₁(cm) 10 30 5.0 30 10 10 d(cm) 40 25 5 f₂(cm) P₂(cm) 5.0 5.0 5.0…
Q: Consider the following Lewis structure where E is an unknown element: :0: :Ö-E- :O: :Ö: î 2- What is…
Q: A merry-go-round at the park starts from rest, and you grab one of the bars on the ride and start…
Q: The period of a simple harmonic oscillator is 0.04 s. What is its angular frequency? A. 25 л rad/s…
Q: 1. Given that a 3.00 nanocoulomb charged particle is moving with a velocity equal to 2.00 × 105 m/s…
Q: 10. Let C(r) be the statement " has a cat," let D(z) be the statement " has a dog," and let F(x) be…
Q: What type of sampling is used? We randomly select one of the 4 sections of statistics and interview…
Q: QUESTION 34 A measure of identifying the effect of an unusual x value on the regression results is…
Q: why can a monopoly earn economic profits in the long run?
Q: An election ballot asks voters to select four city commissioners from a group of ten candidates. In…