Question

In Java Eclipse, create a program Pythagoras which includes a method ‘double getC(double a, double b)’...

In Java Eclipse, create a program Pythagoras which includes a method ‘double getC(double a, double b)’ which would find and return the length of the hypotenuse c given the length of the other sides a and b.

Formula: c= sqrt(a^2+b^2)

Homework Answers

Answer #1

import java.util.Scanner;

public class Pythagoras {

   public static void main(String[] args) {
       Scanner in=new Scanner(System.in);
       //user input
       System.out.println("Enter side a: ");
       double a=in.nextDouble();
      
       System.out.println("Enter side b: ");
       double b=in.nextDouble();
       System.out.println("length of the hypotenuse is: "+getC(a,b));
      

   }
   public static double getC(double a, double b)
   {
       return Math.sqrt(Math.pow(a, 2) + Math.pow(a, 2));
   }

}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Meant to be written in Java JDK 14.0 Three double variables a, b, and c represent...
Meant to be written in Java JDK 14.0 Three double variables a, b, and c represent the length of 3 sides of a triangle. Write a program to determine if the triangle is right triangle. Find the hypotenuse side first.
Write a Java program to display a letter grade based on an actual grade. USING ECLIPSE...
Write a Java program to display a letter grade based on an actual grade. USING ECLIPSE IDE A = 90-100 B = 80-89 C = 70-79 D = 60-69 F = less than 60 The program needs to do the following: 1. Create a short integer to store a grade. (See Week 3 - Things to Know - Java Data Types ) 2. Prompt for a grade ( 0-100). 3. Based on the grade given, use IF statements to display...
Please make a Java program that has a menu method and includes dialog boxes. The program...
Please make a Java program that has a menu method and includes dialog boxes. The program will call the proper method, but each method will be completed later. Your program will keep track of information for a Hospital. The program will be menu-driven. Your menu is to look something like the following: UPMC Medical Center Add/Modify Patient Information Add/Modify Physician Information Add/Modify Medical Information Hospital Report Section Exit the Medical System Please Make your selection > In this first phase,...
(Use JAVA) For this program, you need to create three classes, one of which is a...
(Use JAVA) For this program, you need to create three classes, one of which is a main class that includes aggregation from the other two classes. Each of the classes must include at least two fields, multiple constructors, accessor and mutator methods, and toString. Methods in your main class must include: 1. .equals 2. .copy 3. One that passes an object other than the .copy method 4. One that returns an object 5. toString that calls the toStrings from the...
IN JAVA Complete the following program. Add codes in the main method to:1) call method average(double[]...
IN JAVA Complete the following program. Add codes in the main method to:1) call method average(double[] gpaarr ) to calculate the average of gpaArray; 2) add codes in the for loop to calculate sum 3) print the average . public class Test { public static void main (String args[]) { double[ ] gpaArray = { 2.5, 4.0, 3.8, 3.2, 2.9, 4.0 } ;   //add your codes here (you can put your codes in the Answer area with/without copying the original...
Input the amount of purchase which is less than P100.00. Create a java program that will...
Input the amount of purchase which is less than P100.00. Create a java program that will calculate the change of P100.00 given by the customer with the following breakdown: P 50.00 - _______________; P 20.00 - _______________; P 10.00 - _______________; P 5.00 - _______________; P 1.00 - _______________; Note: Purchases are all in pesos. No centavos. Formula Hint: Apply the concept of modulus operator
Create a class named MyTriangle that contains the following three methods: public static boolean isValid(double sidea,...
Create a class named MyTriangle that contains the following three methods: public static boolean isValid(double sidea, double sideb, double sidec) public static double area(double sidea, double sideb, double sidec) public static String triangletType(double a, double b, double c) The isValid method returns true if the sum of the two shorter sides is greater than the longest side. The lengths of the 3 sides of the triangle are sent to this method but you may NOT assume that they are sent...
Write a C++ program which will prompt as input the value of two sides of a...
Write a C++ program which will prompt as input the value of two sides of a right triangle and then determine the size of the hypotenuse. [Hint: Hypotenuse = square root of (a^2+b^2 ), where a, b are the two sides of a right triangle.]
JAVA PROGRAMMING: Create a program which will calculate and output as formatted output the kilometers or...
JAVA PROGRAMMING: Create a program which will calculate and output as formatted output the kilometers or miles, given as keyboard input the miles or kilometers, as inputted as a double number. That is, the user has a choice what to calculate. The original value inputted should be displayed along with the calculated miles or kilometers. Demonstrate escape sequences, a while loop or a do…while loop, and named constants as needed,  should be implemented. Finally, input, processing, and output must be implemented...
Create a Java Program to calculate luggage costs. The Business Rules are: A. Two bags per...
Create a Java Program to calculate luggage costs. The Business Rules are: A. Two bags per person are free. B. The Excess Bag Charge is $75 per bag. The program needs to do the following: 1. In your main method(),    Create integers to store the number of Passengers and also the total number of bags    Prompt for the number of passengers on a ticket.    Prompt for the total number of bags for all passengers on a ticket....
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT