Write a method called sigma that takes an int parameter n


Question 1) Write a method called sigma that takes an int parameter n and returns the sum of all the integers from 1 to n (inclusive). For example, sigma(4) should return 10.

Question 2) Write a method called distance that takes four double parameters, x1, y1, x2 and y2. x1 and y1 are the coordinates of the first point; x2 and y2 are the coordinates of the second point. The method should return the distance between the two points. Use the Pythagorean theorem.

Question 3) The hailstone sequence begins with some designated integer n (it can be any integer). If n is even, then the next number in the sequence is n/2. If n is odd, then the next number in the sequence is 3 * n + 1.

Write a method called hailstone that takes an int parameter that gives the starting place. The method should return the number of steps that it takes until the sequence arrives at 1. For example: if the method is called with 3 as the parameter, then the sequence would be 3, 10, 5, 16, 8, 4, 2, 1. It takes 7 steps to get from 3 to 1, so the method would return 7.

Please show me all the work and provide me the code.

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: Write a method called sigma that takes an int parameter n
Reference No:- TGS0945034

Expected delivery within 24 Hours