Advertisement
kaosamal

evaluacion

Feb 25th, 2020
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.18 KB | None | 0 0
  1.  
  2. package palindromo;
  3.  
  4. public class Palindromo2 {
  5.  
  6.     public boolean espalindromo(String cadena) {
  7.         boolean valor = true;
  8.         int i, ind;
  9.         String cadena2 = "";
  10. //quitamos los espacios
  11.         for (int x = 0; x < cadena.length(); x++) {
  12.             if (cadena.charAt(x) != ' ') {
  13.                 cadena2 += cadena.charAt(x);
  14.             }
  15.         }
  16. //volvemos a asignar variables
  17.         cadena = cadena2;
  18.         ind = cadena.length();
  19. //comparamos cadenas
  20.         for (i = 0; i < (cadena.length()); i++) {
  21.             if (cadena.substring(i, i + 1).equals(cadena.substring(ind - 1, ind)) == false) {
  22. //si una sola letra no corresponde no es un palindromo por tanto
  23. //sale del ciclo con valor false
  24.                 valor = false;
  25.                 break;
  26.             }
  27.             ind--;
  28.         }
  29.         return valor;
  30.     }
  31. }
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39. package palindromo;
  40.  
  41. import java.util.Scanner;
  42.  
  43.  
  44.  
  45. public class main {
  46. public static void main(String[] args) {
  47. Scanner tc = new Scanner(System.in);
  48.     int day;
  49.     System.out.print("Escoje la opcion 1 Palindromo o 2 Vectores");
  50.     day = tc.nextInt();
  51.    
  52.    
  53.     switch (day) {
  54.       case 1:
  55.         System.out.println("Palindromo");
  56.         palindromo objclass=new palindromo();
  57.         break;
  58.       case 2:
  59.         System.out.println("Vectores");
  60.         Scanner sc = new Scanner(System.in);
  61.         int o;
  62.         int elemA = 0;
  63.         int pos = 0, neg = 0; //contadores de los números positivos y negativos
  64.         int[] numeros = new int[10]; //array que contendrá los números leídos por teclado
  65.         double sumaPos = 0, sumaNeg = 0; //acumuladores para las sumas de positivos y negativos
  66.  
  67.         //lectura de datos y llenar el array
  68.         System.out.println("Lectura de los elementos del array: ");
  69.         for (o = 0; o < 10; o++) {
  70.             System.out.print("numeros[" + o + "]= ");
  71.             numeros[o] = sc.nextInt();
  72.         }
  73.  
  74.  
  75.  
  76.         for (int i = 0; i < numeros.length; i++) {
  77.             for (int j = 0; j < numeros.length; j++) {
  78.                 if (numeros[i] == numeros[j]) {
  79.                     elemA++;
  80.                 }
  81.             }
  82.             System.out.println("El elemento " + numeros[i] + " se presenta " + elemA + " veces repetido");
  83.             elemA = 0;
  84.         }
  85.         break;
  86.  
  87.     }
  88. }
  89. }
  90.  
  91.  
  92.  
  93. package palindromo;
  94.  
  95. import java.util.Arrays;
  96. import java.util.Scanner;
  97.  
  98. public class palindromo {
  99.  
  100.     public static void main(String[] args) {
  101.         Scanner tc = new Scanner(System.in);
  102.         int day;
  103.         System.out.println("Escoje la opcion \n1 Palindromo \n2 Vectores \n:");
  104.         day = tc.nextInt();
  105.  
  106.         switch (day) {
  107.             case 1:
  108.                 System.out.println("Palindromo");
  109.                 Scanner teclado = new Scanner(System.in);
  110.                 String nuevo;
  111.                 Palindromo2 objclass = new Palindromo2();
  112.                 System.out.println("Ingresa la palabra");
  113.                 nuevo = teclado.nextLine();
  114.                 if (objclass.espalindromo(nuevo)) {
  115.                     System.out.println("Palindromo");
  116.                 } else {
  117.                     System.out.println("No Palindromo");
  118.                 }
  119.                 break;
  120.             case 2:
  121.                 System.out.println("Vectores");
  122.                 Scanner sc = new Scanner(System.in);
  123.                 int o;
  124.                 int elemA = 0;
  125.                 int pos = 0,
  126.                 neg = 0; //contadores de los números positivos y negativos
  127.                 int[] numeros = new int[12]; //array que contendrá los números leídos por teclado
  128.                 double sumaPos = 0,
  129.                 sumaNeg = 0; //acumuladores para las sumas de positivos y negativos
  130.  
  131.                 //lectura de datos y llenar el array
  132.                 System.out.println("Lectura de los elementos del array: ");
  133.                 for (o = 0; o < 12; o++) {
  134.                     System.out.print("numeros[" + o + "]= ");
  135.                     numeros[o] = sc.nextInt();
  136.                 }
  137.  
  138.                 for (int i = 0; i < numeros.length; i++) {
  139.                     for (int j = 0; j < numeros.length; j++) {
  140.                         if (numeros[i] == numeros[j]) {
  141.                             elemA++;
  142.                         }
  143.                     }
  144.                     System.out.print(numeros[o]);
  145.                     System.out.println("El elemento " + numeros[i] + " se presenta " + elemA + " veces repetido");
  146.                     elemA = 0;
  147.                 }
  148.                
  149.                
  150.                 for (int i = 0; i < numeros.length; i++) {
  151.                     for (int j = 0; j < numeros.length; j++) {
  152.                         if (numeros[i] == numeros[j]) {
  153.                             elemA++;
  154.                         }
  155.                     }
  156.                     System.out.println("Numeros Repetidos" +numeros[i] + elemA);
  157.                     elemA = 0;
  158.                    
  159.                 }
  160.                 break;
  161.  
  162.         }
  163.  
  164.     }
  165.  
  166. }
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175. package palindromo;
  176.  
  177. import java.util.Scanner;
  178.  
  179. public class vectores {
  180.  
  181.     public static void main(String[] args) {
  182.         Scanner sc = new Scanner(System.in);
  183.         int o;
  184.         int elemA = 0;
  185.         int pos = 0, neg = 0; //contadores de los números positivos y negativos
  186.         int[] numeros = new int[10]; //array que contendrá los números leídos por teclado
  187.         double sumaPos = 0, sumaNeg = 0; //acumuladores para las sumas de positivos y negativos
  188.  
  189.         //lectura de datos y llenar el array
  190.         System.out.println("Lectura de los elementos del array: ");
  191.         for (o = 0; o < 10; o++) {
  192.             System.out.print("numeros[" + o + "]= ");
  193.             numeros[o] = sc.nextInt();
  194.         }
  195.  
  196.  
  197.  
  198.         for (int i = 0; i < numeros.length; i++) {
  199.             for (int j = 0; j < numeros.length; j++) {
  200.                 if (numeros[i] == numeros[j]) {
  201.                     elemA++;
  202.                 }
  203.             }
  204.             System.out.println("El elemento " + numeros[i] + " se presenta " + elemA + " veces repetido");
  205.             elemA = 0;
  206.         }
  207.        
  208.        
  209.     }
  210. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement