Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- import java.util.Scanner;
- public class PuntoSeis {
- public static void main(String[] args) {
- int a,b,c, opc = 0;
- Scanner sn = new Scanner(System.in);
- while (opc != 3) {
- menu();
- opc=validar(sn,"Seleccione una opcion.");
- switch (opc) {
- case 1:
- a = validar(sn, "Ingrese lado A del triangulo.");
- b = validar(sn, "Ingrese lado B del triangulo.");
- c = validar(sn, "Ingrese lado C del triangulo.");
- triangulo(a,b,c);
- break;
- case 2:
- System.out.println("Generando valores random [0-10]para A,B y C.");
- Random ar= new Random();
- int ar1 = ar.nextInt();
- Random br = new Random();
- int br1 = br.nextInt();
- Random cr = new Random();
- int cr1 = br.nextInt();
- triangulo(ar1,br1,cr1);
- break;
- case 3:
- System.out.println("Finalizando programa");
- break;
- default:
- System.out.println("Ingrese una opcion valida.");
- }
- }
- }
- public static void menu() {
- System.out.println("Clasificacion de triangulos");
- System.out.println("1 - Ingreso de datos.");
- System.out.println("2 - Numeros al azar.");
- System.out.println("3 - Finalizar");
- }
- public static int validar(Scanner b, String ingreso) {
- int numero;
- String linea;
- while (true) {
- try {
- System.out.println(ingreso);
- linea=b.nextLine();
- numero=Integer.parseInt(linea);
- break;
- }
- catch(Exception e){
- System.out.println("Error: Ingrese un numero.");
- }
- }
- return numero;
- }
- public static void triangulo(int x, int y, int z) {
- if ((x+y>z) || (x+z>y) || (y+z>x)) {
- if ((x == y) && (x == z) && (y == z))
- System.out.println("Los lados ingresados forman un Triángulo equilátero.");
- else if ((x != y) && (x != z) && (y != z))
- System.out.println("Los lados ingresados forman un Triángulo escaleno.");
- else
- System.out.println("Los lados ingresados forman un Triángulo isósceles.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment