Alexis-Coria

Untitled

Aug 30th, 2021
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. import java.util.Random;
  2. import java.util.Scanner;
  3.  
  4. public class PuntoSeis {
  5.  
  6. public static void main(String[] args) {
  7. int a,b,c, opc = 0;
  8. Scanner sn = new Scanner(System.in);
  9.  
  10. while (opc != 3) {
  11. menu();
  12. opc=validar(sn,"Seleccione una opcion.");
  13. switch (opc) {
  14. case 1:
  15. a = validar(sn, "Ingrese lado A del triangulo.");
  16. b = validar(sn, "Ingrese lado B del triangulo.");
  17. c = validar(sn, "Ingrese lado C del triangulo.");
  18. triangulo(a,b,c);
  19. break;
  20. case 2:
  21. System.out.println("Generando valores random [0-10]para A,B y C.");
  22. Random ar= new Random();
  23. int ar1 = ar.nextInt();
  24. Random br = new Random();
  25. int br1 = br.nextInt();
  26. Random cr = new Random();
  27. int cr1 = br.nextInt();
  28. triangulo(ar1,br1,cr1);
  29. break;
  30. case 3:
  31. System.out.println("Finalizando programa");
  32. break;
  33. default:
  34. System.out.println("Ingrese una opcion valida.");
  35. }
  36. }
  37.  
  38.  
  39. }
  40.  
  41.  
  42. public static void menu() {
  43. System.out.println("Clasificacion de triangulos");
  44. System.out.println("1 - Ingreso de datos.");
  45. System.out.println("2 - Numeros al azar.");
  46. System.out.println("3 - Finalizar");
  47.  
  48. }
  49.  
  50.  
  51. public static int validar(Scanner b, String ingreso) {
  52. int numero;
  53. String linea;
  54. while (true) {
  55. try {
  56. System.out.println(ingreso);
  57. linea=b.nextLine();
  58. numero=Integer.parseInt(linea);
  59. break;
  60. }
  61. catch(Exception e){
  62. System.out.println("Error: Ingrese un numero.");
  63. }
  64. }
  65. return numero;
  66. }
  67.  
  68.  
  69.  
  70. public static void triangulo(int x, int y, int z) {
  71. if ((x+y>z) || (x+z>y) || (y+z>x)) {
  72. if ((x == y) && (x == z) && (y == z))
  73. System.out.println("Los lados ingresados forman un Triángulo equilátero.");
  74. else if ((x != y) && (x != z) && (y != z))
  75. System.out.println("Los lados ingresados forman un Triángulo escaleno.");
  76. else
  77. System.out.println("Los lados ingresados forman un Triángulo isósceles.");
  78. }
  79.  
  80. }
  81.  
  82. }
  83.  
Advertisement
Add Comment
Please, Sign In to add comment