Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public double Calculouno(double x1,double x2,double y1,double y2)
- {
- double ecuacion1;
- ecuacion1= (x2-x1)+(y2-y1);
- ecuacion1= Math.sqrt(ecuacion1);
- return ecuacion1;
- }
- import java.util.Scanner;
- import java.lang.Math;
- public class Ejercicio12
- {
- public static void main(String args[])
- {
- double[] x= new double[3];
- double[] y= new double[3];
- double a,b,c;
- int con=0, con2=0;
- double[] angulo= new double[3];
- Scanner entrada = new Scanner(System.in);
- Calculos cal= new Calculos();
- for(con=0;con<3;con++)
- {
- System.out.println("Ingrese un valor x para el punto "+(con+1)+": ");
- x[con]= entrada.nextDouble();
- System.out.println("Ingrese un valor y para el punto "+(con+1)+": ");
- y[con]= entrada.nextDouble();
- }
- a= cal.Calculouno(x[0],x[1],y[0],y[1]);
- b= cal.Calculouno(x[1],x[2],y[1],y[2]);
- c= cal.Calculouno(x[2],x[0],y[2],y[0]);
- angulo[0]= cal.Angulo(a,b,c);
- angulo[1]= cal.Angulo(c,a,b);
- angulo[2]= cal.Angulo(b,a,c);
- if(angulo[0]>90||angulo[1]>90||angulo[2]>90)
- {
- System.out.println("El triangulo es obtusangulo");
- }
- else
- {
- if(angulo[0]==90||angulo[1]==90||angulo[2]==90)
- {
- System.out.println("El triangulo es rectangulo");
- }
- else
- {
- if(angulo[0]<90&&angulo[1]<90&&angulo[2]<90)
- {
- System.out.println("El triangulo es acutangulo");
- }
- }
- }
- }
- }
- import static java.lang.Math.sqrt;
- import static java.lang.Math.pow;
- import static java.lang.Math.acos;
- public class Calculos
- {
- public double Calculouno(double x1,double x2,double y1,double y2)
- {
- double ecuacion1;
- double dx= (x2-x1);
- double dy= (y2-y1);
- return Math.sqrt(dy+dx);
- }
- public double Angulo(double a1,double b1, double c1)
- {
- double ecuacion2;
- double a11 = pow(a1,2);
- double b11 = pow(b1,2);
- double c11 = pow(c1,1);
- double xx=(b11+c11-a11);
- double zz=(2*b1*c1);
- return Math.acos(xx/zz);
- }
- }
- double x = 0.0 / 0.0; // generate a NaN
- System.out.println(0.0 == x);
- System.out.println(0.0 != x);
- System.out.println(0.0 < x);
- System.out.println(0.0 > x);
- System.out.println(x == x);
- System.out.println(x != x);
- System.out.println(x < x);
- System.out.println(x > x);
- package cruft;
- /**
- * Junk description here
- * @author Michael
- * @link
- * @since 9/8/12 10:19 PM
- */
- public class Triangle {
- private final Point p1;
- private final Point p2;
- private final Point p3;
- public static void main(String args[]) {
- if (args.length > 5) {
- Point p1 = new Point(Double.valueOf(args[0]), Double.valueOf(args[1]));
- Point p2 = new Point(Double.valueOf(args[2]), Double.valueOf(args[3]));
- Point p3 = new Point(Double.valueOf(args[4]), Double.valueOf(args[5]));
- Triangle triangle = new Triangle(p1, p2, p3);
- double angle = triangle.calculateAngle();
- System.out.println(triangle);
- if (angle > 0.0) {
- System.out.println("obtuse");
- } else if (angle < 0.0) {
- System.out.println("acute");
- } else {
- System.out.println("right triangle");
- }
- } else {
- System.out.println("Usage: Triangle x1 y1 x2 y2 x3 y3");
- }
- }
- public Triangle(Point p1, Point p2, Point p3) {
- this.p1 = p1;
- this.p2 = p2;
- this.p3 = p3;
- }
- public double calculateAngle(){
- double a = Point.distance(this.p1, this.p2);
- double b = Point.distance(this.p2, this.p3);
- double c = Point.distance(this.p3, this.p1);
- return Math.acos(a*a + b*b - c*c)/2.0/a/b;
- }
- @Override
- public String toString() {
- final StringBuilder sb = new StringBuilder();
- sb.append("Triangle");
- sb.append("{p1=").append(p1);
- sb.append(", p2=").append(p2);
- sb.append(", p3=").append(p3);
- sb.append('}');
- return sb.toString();
- }
- }
- class Point {
- public final double x;
- public final double y;
- public Point(double x, double y) {
- this.x = x;
- this.y = y;
- }
- public static double distance(Point q1, Point q2) {
- double dx = Math.abs(q1.x-q2.x);
- double dy = Math.abs(q1.y-q2.y);
- if (dx > dy) {
- double r = dy/dx;
- return dx*Math.sqrt(1.0+r*r);
- } else {
- double r = dx/dy;
- return dy*Math.sqrt(1.0+r*r);
- }
- }
- @Override
- public String toString() {
- final StringBuilder sb = new StringBuilder();
- sb.append('(').append(x);
- sb.append(',').append(y);
- sb.append(')');
- return sb.toString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement