Advertisement
AmbarG

PUNTO3 TP0

Aug 26th, 2021
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.82 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class tresitooo {
  3.  
  4.     private static int opcion;
  5.  
  6.     public static void main(String[] args) {
  7.         Scanner leer = new Scanner(System.in);
  8.         Teclado in = new Teclado();
  9.        
  10.         System.out.println("1 = Ingrese los numeros");
  11.         System.out.println("2 = Numeros aleatorios");
  12.         System.out.println("3 = salir");
  13.        
  14.         int opcion = in.getInt("Seleccione una opcion");
  15.         opciones(opcion);
  16.        
  17.        
  18.        
  19.     }
  20.    
  21.     public static void opciones(int opciones){
  22.         switch(opcion) {
  23.             case 1:
  24.                 int a, b, i, sumaA, sumaB;
  25.                 sumaA=0;
  26.                 sumaB=0;
  27.                 System.out.println("Ingrese un numero: ");
  28.                 a = leer.nextInt();
  29.                 System.out.println("Ingrese un numero: ");
  30.                 b = leer.nextInt();
  31.                 for(i=1; i<a; i++){
  32.                     if(a % i==a){
  33.                         sumaA = sumaA +1;
  34.                     }
  35.                 }
  36.                 for(i=1; i<b; i++){
  37.                     if (b % i == 0){
  38.                         sumaB = sumaB + 1;
  39.                     }
  40.                 }
  41.                
  42.                 if (sumaA == b && sumaB == a){
  43.                     System.out.println("Son amigos");
  44.                    
  45.                 }else{
  46.                     System.out.println("No son amigos");
  47.                 }
  48.                 break;
  49.             case 2:
  50.                 int aleatorio = 0;
  51.                 int aleatorioo = 0;
  52.                 aleatorio = (int) (Math.random() * 500);
  53.                 System.out.println(aleatorio);
  54.                 aleatorioo = (int) (Math.random() *500);
  55.                 System.out.println(aleatorioo);
  56.                 int aleatorio, aleatorioo, i, sumaAleatorio, sumaAleatorioo;
  57.                 sumaA=0;
  58.                 sumaB=0;
  59.                 System.out.println("Ingrese un numero: ");
  60.                 aleatorio = leer.nextInt();
  61.                 System.out.println("Ingrese un numero: ");
  62.                 aleatorioo = leer.nextInt();
  63.                 for(i=1; i<aleatorio; i++){
  64.                     if(aleatorio % i==aleatorio){
  65.                         sumaA = sumaA +1;
  66.                     }
  67.                 }
  68.                 for(i=1; i<aleatorioo; i++){
  69.                     if (aleatorioo % i == 0){
  70.                         sumaB = sumaB + 1;
  71.                     }
  72.                 }
  73.                
  74.                 if (sumaA == aleatorioo && sumaB == aleatorio){
  75.                     System.out.println("Son amigos");
  76.                    
  77.                 }else{
  78.                     System.out.println("No son amigos");
  79.                 }
  80.                 break;
  81.             case 3:
  82.                 System.exit(0);
  83.                 break;
  84.         }
  85.     }
  86.    
  87. }
  88.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement