Law Of Cosines
Page 1 of 1
Law Of Cosines
Moooo Trig!!
- Code:
import java.util.Scanner;
/**
*
* @author petahwil
*/
public class LawOfCosines {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner in = new Scanner(System.in);
System.out.print("Enter if you would like the answer in Rad or Deg: ");
String mode = in.next();
boolean check = true;
if ("Rad".equals(mode))
{
check = true;
}
else if ("Deg".equals(mode))
{
check = true;
}
else
{
System.out.println("Wrong Format Input Rad or Deg!");
check = true;
System.exit(1);
}
System.out.print("Enter in what you are solving for (a,b,c): ");
String input = in.next();
String lower = input;
String lower2 = "";
String Upper = "";
if ("a".equals(input)) {
lower = "b";
lower2 = "c";
Upper = "A";
}
else if ("b".equals(input)) {
lower = "a";
lower2 = "c";
Upper = "B";
}
else if ("c".equals(input)) {
lower = "a";
lower2 = "b";
Upper = "C";
}
else{
System.out.println("Wrong Format");
System.exit(1);
}
System.out.print("Enter in " + Upper + " vaule: ");
int A = in.nextInt();
System.out.print("Enter in " + lower + " vaule: ");
int a = in.nextInt();
System.out.print("Enter in " + lower2 + " vaule: ");
int b = in.nextInt();
if ("Rad".equals(mode)){
double asine = Math.sin(A);
double equation = Math.pow(a, 2)+Math.pow(b, 2)-2*a*b*asine;
double equ = Math.sqrt(equation);
System.out.print(input+" = "+equ);
}
if ("Deg".equals(mode)){
double asine = Math.cos(Math.toRadians(A));
double equation = Math.pow(a, 2)+Math.pow(b, 2)-2*a*b*asine;
double equ = Math.sqrt(equation);
System.out.print(input+" = "+equ);
}
}
}
Petahwil- Posts : 8
Join date : 2012-11-30
Age : 31
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
Sat Feb 15, 2014 10:12 am by doriperni
» Sync2 V2.20.1312 X86x64.rar.rar
Fri Feb 14, 2014 7:37 pm by carmibire
» 9.1 Inheritance Hierarchies
Tue Feb 26, 2013 12:50 pm by ThienDinh
» Useful website
Sat Dec 08, 2012 6:52 pm by tpham1991
» The Machine that Changed the World: Giant Brains. 1992 Documentary
Sat Dec 08, 2012 2:16 am by ThienDinh
» Problems in practice test.
Thu Dec 06, 2012 2:32 pm by ThienDinh
» Newton's Method
Mon Dec 03, 2012 8:32 pm by ThienDinh
» Console Calc
Sun Dec 02, 2012 5:57 pm by Petahwil
» Law Of Cosines
Sat Dec 01, 2012 4:54 pm by Petahwil