# Geometry: Display angles of a triangle

Page 1 of 1

## 4 Replies - 2317 Views - Last Post: 06 October 2013 - 10:44 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=330803&amp;s=dbfd74049115194cd7dd54409376ce5f&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 coxxie

Reputation: 0
• Posts: 17
• Joined: 29-October 11

# Geometry: Display angles of a triangle

Posted 05 October 2013 - 11:02 AM

(Geometry: display angles) Write a program that prompts the user to enter three
points of a triangle and displays the angles in degrees. Round the value to keep
two digits after the decimal point. The formula to compute angles A, B, and C are
as follows:

A = arccos((a * a - b * b - c * c) / (-2 * b * c))
B = arccos((b * b - a * a - c * c) / (-2 * a * c))
C = arccos((c * c - b * b - a * a) / (-2 * a * />/>)

Here is a sample run of the program:

Enter three points: 6.5 6.5 2.5
The three angles are 15.26 90.0 74.74

Here is my code so far: I am having trouble trying to take in three variables, pass them to the method and then return them.
```/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package pkg5.pkg23;

/**
*
* @author Coxxie
*/
import java.util.Scanner;

public class Main
{

/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter 3 sides of a triangle: \n");
System.out.print("Enter side A of a triangle: \n");
double sideA = input.nextInt();
System.out.print("Enter side B of a triangle: \n");
double sideB = input.nextInt();
System.out.print("Enter side C of a triangle: \n");
double sideC = input.nextInt();

double anglel = angleA(sideA, sideB, sideC);
double angle2 = angleB(sideA, sideB, sideC);
double angle3 = angleC(sideA, sideB, sideC);

System.out.println
("The three angles are: " + angleA(anglel) + " "+ angleB(angle2) + " " + angleC(angle3));

}

public static double angleA(double sideA, double sideB, double sideC)
{
//figA = equation in book. Imput it in and copy in sides.
double angA = Math.acos((sideA * sideA - sideB * sideB - sideC * sideC) / (-2 * sideB * sideC));

return angA;
}

public static double angleB(double sideA, double sideB, double sideC)
{
//figA = equation in book. Imput it in and copy in sides.
double angB = Math.acos((sideA * sideA - sideB * sideB - sideC * sideC) / (-2 * sideB * sideC));

return angB;
}

public static double angleC(double sideA, double sideB, double sideC)
{
//figA = equation in book. Imput it in and copy in sides.
double angC = Math.acos((sideA * sideA - sideB * sideB - sideC * sideC) / (-2 * sideB * sideC));

return angC;
}
}
```

This post has been edited by jon.kiparsky: 05 October 2013 - 11:15 AM
Reason for edit:: [code] tags

Is This A Good Question/Topic? 0

## Replies To: Geometry: Display angles of a triangle

### #2 Mylo

• Knows all, except most.

Reputation: 265
• Posts: 747
• Joined: 11-October 11

## Re: Geometry: Display angles of a triangle

Posted 05 October 2013 - 11:32 AM

Why are you making your code about sides? Aren't you supposed to be entering points?

Quote

I am having trouble trying to take in three variables, pass them to the method and then return them.

You seem to have done all of these already. Apart from here:
``` System.out.println("The three angles are: " + angleA(anglel) + " "+ angleB(angle2) + " " + angleC(angle3));
```

in which case, this is what was probably intended:
``` System.out.println("The three angles are: " + anglel + " "+ angle2 + " " + angle3);
```

This post has been edited by Mylo: 05 October 2013 - 11:43 AM

### #3 schutzzz

• D.I.C Regular

Reputation: 138
• Posts: 338
• Joined: 22-April 13

## Re: Geometry: Display angles of a triangle

Posted 05 October 2013 - 12:43 PM

Your methods angleA, angleB, and angleC each require 3 parameters. You're only giving them each one.

### #4 pbl

• There is nothing you can't do with a JTable

Reputation: 8347
• Posts: 31,913
• Joined: 06-March 08

## Re: Geometry: Display angles of a triangle

Posted 05 October 2013 - 06:04 PM

why 3 methods angleA(), angleB() and angleC() that do exactly the same thing ?
You need only one named angle()

### #5 coxxie

Reputation: 0
• Posts: 17
• Joined: 29-October 11

## Re: Geometry: Display angles of a triangle

Posted 06 October 2013 - 10:44 AM

I was focusing to much on the diagram provided for the and didn't read the problem though all the way. I was focusing on sides and not points of the triangle. When I get my code updated I will up load it.

Thanks for the pointers so far.