I\'m having a bit of a trouble with my java code. It does what i want it to do b
ID: 3557785 • Letter: I
Question
I'm having a bit of a trouble with my java code. It does what i want it to do but i get an error message saying
how would i go about fixing this?
// this is my code
import java.io.*;
import java.util.*;
public class Cos {
static Scanner console = new Scanner (System.in);
public static void main (String [] args) {
int a;
int b;
int C;
double c;
double B;
double A;
System.out.print("Enter the lengths of three sides of a triangle with spaces between, then hit enter");
System.out.println();
a = console.nextInt();
b = console.nextInt();
C= console.nextInt();
c=Math.toDegrees(Math.acos((b * b + C * C - a * a)/(2.0 * b * C)));
B=Math.toDegrees(Math.acos((a * a + b * b - C * C)/(2.0 * a * b)));
A=Math.toDegrees(Math.acos((C * C + a * a - b * b)/(2.0 * C * a)));
System.out.println("Side of length " +a + " is across from angle "+c);
System.out.println("Side of length " +b + " is across from angle "+A);
System.out.println("Side of length " +C + " is across from angle "+B);
}
}
Explanation / Answer
//your program does not have a method named getAngleFromSides that returns a double and expects three double parameters
// this is my code TO FIX THE BUG ADD THAT METHOD WITH REQUIRED HEADER.
import java.io.*;
import java.util.*;
public class Cos {
static Scanner console = new Scanner (System.in);
public static void main (String [] args) {
int a;
int b;
int C;
double c;
double B;
double A;
System.out.print("Enter the lengths of three sides of a triangle with spaces between, then hit enter");
System.out.println();
a = console.nextInt();
b = console.nextInt();
C= console.nextInt();
c=getAngleFromSides(b,C,a);
B=getAngleFromSides(a,b,C);
A=getAngleFromSides(C,a,b);
System.out.println("Side of length " +a + " is across from angle "+c);
System.out.println("Side of length " +b + " is across from angle "+A);
System.out.println("Side of length " +C + " is across from angle "+B);
}
public static double getAngleFromSides(double a,double b,double c)
{
return Math.toDegrees(Math.acos((a * a + b * b - C * C)/(2.0 * a * b)));
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.