Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.00 KB | None | 0 0
  1. public double Calculouno(double x1,double x2,double y1,double y2)
  2. {
  3. double ecuacion1;
  4. ecuacion1= (x2-x1)+(y2-y1);
  5. ecuacion1= Math.sqrt(ecuacion1);
  6. return ecuacion1;
  7. }
  8.  
  9. import java.util.Scanner;
  10. import java.lang.Math;
  11.  
  12. public class Ejercicio12
  13. {
  14. public static void main(String args[])
  15. {
  16. double[] x= new double[3];
  17. double[] y= new double[3];
  18. double a,b,c;
  19. int con=0, con2=0;
  20. double[] angulo= new double[3];
  21. Scanner entrada = new Scanner(System.in);
  22. Calculos cal= new Calculos();
  23.  
  24. for(con=0;con<3;con++)
  25. {
  26. System.out.println("Ingrese un valor x para el punto "+(con+1)+": ");
  27. x[con]= entrada.nextDouble();
  28. System.out.println("Ingrese un valor y para el punto "+(con+1)+": ");
  29. y[con]= entrada.nextDouble();
  30. }
  31.  
  32. a= cal.Calculouno(x[0],x[1],y[0],y[1]);
  33. b= cal.Calculouno(x[1],x[2],y[1],y[2]);
  34. c= cal.Calculouno(x[2],x[0],y[2],y[0]);
  35.  
  36. angulo[0]= cal.Angulo(a,b,c);
  37. angulo[1]= cal.Angulo(c,a,b);
  38. angulo[2]= cal.Angulo(b,a,c);
  39.  
  40. if(angulo[0]>90||angulo[1]>90||angulo[2]>90)
  41. {
  42. System.out.println("El triangulo es obtusangulo");
  43. }
  44. else
  45. {
  46. if(angulo[0]==90||angulo[1]==90||angulo[2]==90)
  47. {
  48. System.out.println("El triangulo es rectangulo");
  49. }
  50. else
  51. {
  52. if(angulo[0]<90&&angulo[1]<90&&angulo[2]<90)
  53. {
  54. System.out.println("El triangulo es acutangulo");
  55. }
  56. }
  57.  
  58. }
  59. }
  60.  
  61.  
  62. }
  63.  
  64.  
  65.  
  66. import static java.lang.Math.sqrt;
  67. import static java.lang.Math.pow;
  68. import static java.lang.Math.acos;
  69. public class Calculos
  70. {
  71. public double Calculouno(double x1,double x2,double y1,double y2)
  72. {
  73. double ecuacion1;
  74. double dx= (x2-x1);
  75. double dy= (y2-y1);
  76. return Math.sqrt(dy+dx);
  77.  
  78. }
  79.  
  80.  
  81. public double Angulo(double a1,double b1, double c1)
  82. {
  83. double ecuacion2;
  84. double a11 = pow(a1,2);
  85. double b11 = pow(b1,2);
  86. double c11 = pow(c1,1);
  87.  
  88. double xx=(b11+c11-a11);
  89. double zz=(2*b1*c1);
  90.  
  91. return Math.acos(xx/zz);
  92. }
  93.  
  94. }
  95.  
  96. double x = 0.0 / 0.0; // generate a NaN
  97. System.out.println(0.0 == x);
  98. System.out.println(0.0 != x);
  99. System.out.println(0.0 < x);
  100. System.out.println(0.0 > x);
  101. System.out.println(x == x);
  102. System.out.println(x != x);
  103. System.out.println(x < x);
  104. System.out.println(x > x);
  105.  
  106. package cruft;
  107.  
  108. /**
  109. * Junk description here
  110. * @author Michael
  111. * @link
  112. * @since 9/8/12 10:19 PM
  113. */
  114.  
  115. public class Triangle {
  116.  
  117. private final Point p1;
  118. private final Point p2;
  119. private final Point p3;
  120.  
  121. public static void main(String args[]) {
  122. if (args.length > 5) {
  123. Point p1 = new Point(Double.valueOf(args[0]), Double.valueOf(args[1]));
  124. Point p2 = new Point(Double.valueOf(args[2]), Double.valueOf(args[3]));
  125. Point p3 = new Point(Double.valueOf(args[4]), Double.valueOf(args[5]));
  126. Triangle triangle = new Triangle(p1, p2, p3);
  127. double angle = triangle.calculateAngle();
  128. System.out.println(triangle);
  129. if (angle > 0.0) {
  130. System.out.println("obtuse");
  131. } else if (angle < 0.0) {
  132. System.out.println("acute");
  133. } else {
  134. System.out.println("right triangle");
  135. }
  136. } else {
  137. System.out.println("Usage: Triangle x1 y1 x2 y2 x3 y3");
  138. }
  139. }
  140.  
  141. public Triangle(Point p1, Point p2, Point p3) {
  142. this.p1 = p1;
  143. this.p2 = p2;
  144. this.p3 = p3;
  145. }
  146.  
  147. public double calculateAngle(){
  148. double a = Point.distance(this.p1, this.p2);
  149. double b = Point.distance(this.p2, this.p3);
  150. double c = Point.distance(this.p3, this.p1);
  151. return Math.acos(a*a + b*b - c*c)/2.0/a/b;
  152. }
  153.  
  154. @Override
  155. public String toString() {
  156. final StringBuilder sb = new StringBuilder();
  157. sb.append("Triangle");
  158. sb.append("{p1=").append(p1);
  159. sb.append(", p2=").append(p2);
  160. sb.append(", p3=").append(p3);
  161. sb.append('}');
  162. return sb.toString();
  163. }
  164. }
  165.  
  166. class Point {
  167. public final double x;
  168. public final double y;
  169.  
  170. public Point(double x, double y) {
  171. this.x = x;
  172. this.y = y;
  173. }
  174.  
  175. public static double distance(Point q1, Point q2) {
  176. double dx = Math.abs(q1.x-q2.x);
  177. double dy = Math.abs(q1.y-q2.y);
  178. if (dx > dy) {
  179. double r = dy/dx;
  180. return dx*Math.sqrt(1.0+r*r);
  181. } else {
  182. double r = dx/dy;
  183. return dy*Math.sqrt(1.0+r*r);
  184. }
  185. }
  186.  
  187. @Override
  188. public String toString() {
  189. final StringBuilder sb = new StringBuilder();
  190. sb.append('(').append(x);
  191. sb.append(',').append(y);
  192. sb.append(')');
  193. return sb.toString();
  194. }
  195. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement