Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package palindromo;
- public class Palindromo2 {
- public boolean espalindromo(String cadena) {
- boolean valor = true;
- int i, ind;
- String cadena2 = "";
- //quitamos los espacios
- for (int x = 0; x < cadena.length(); x++) {
- if (cadena.charAt(x) != ' ') {
- cadena2 += cadena.charAt(x);
- }
- }
- //volvemos a asignar variables
- cadena = cadena2;
- ind = cadena.length();
- //comparamos cadenas
- for (i = 0; i < (cadena.length()); i++) {
- if (cadena.substring(i, i + 1).equals(cadena.substring(ind - 1, ind)) == false) {
- //si una sola letra no corresponde no es un palindromo por tanto
- //sale del ciclo con valor false
- valor = false;
- break;
- }
- ind--;
- }
- return valor;
- }
- }
- package palindromo;
- import java.util.Scanner;
- public class main {
- public static void main(String[] args) {
- Scanner tc = new Scanner(System.in);
- int day;
- System.out.print("Escoje la opcion 1 Palindromo o 2 Vectores");
- day = tc.nextInt();
- switch (day) {
- case 1:
- System.out.println("Palindromo");
- palindromo objclass=new palindromo();
- break;
- case 2:
- System.out.println("Vectores");
- Scanner sc = new Scanner(System.in);
- int o;
- int elemA = 0;
- int pos = 0, neg = 0; //contadores de los números positivos y negativos
- int[] numeros = new int[10]; //array que contendrá los números leídos por teclado
- double sumaPos = 0, sumaNeg = 0; //acumuladores para las sumas de positivos y negativos
- //lectura de datos y llenar el array
- System.out.println("Lectura de los elementos del array: ");
- for (o = 0; o < 10; o++) {
- System.out.print("numeros[" + o + "]= ");
- numeros[o] = sc.nextInt();
- }
- for (int i = 0; i < numeros.length; i++) {
- for (int j = 0; j < numeros.length; j++) {
- if (numeros[i] == numeros[j]) {
- elemA++;
- }
- }
- System.out.println("El elemento " + numeros[i] + " se presenta " + elemA + " veces repetido");
- elemA = 0;
- }
- break;
- }
- }
- }
- package palindromo;
- import java.util.Arrays;
- import java.util.Scanner;
- public class palindromo {
- public static void main(String[] args) {
- Scanner tc = new Scanner(System.in);
- int day;
- System.out.println("Escoje la opcion \n1 Palindromo \n2 Vectores \n:");
- day = tc.nextInt();
- switch (day) {
- case 1:
- System.out.println("Palindromo");
- Scanner teclado = new Scanner(System.in);
- String nuevo;
- Palindromo2 objclass = new Palindromo2();
- System.out.println("Ingresa la palabra");
- nuevo = teclado.nextLine();
- if (objclass.espalindromo(nuevo)) {
- System.out.println("Palindromo");
- } else {
- System.out.println("No Palindromo");
- }
- break;
- case 2:
- System.out.println("Vectores");
- Scanner sc = new Scanner(System.in);
- int o;
- int elemA = 0;
- int pos = 0,
- neg = 0; //contadores de los números positivos y negativos
- int[] numeros = new int[12]; //array que contendrá los números leídos por teclado
- double sumaPos = 0,
- sumaNeg = 0; //acumuladores para las sumas de positivos y negativos
- //lectura de datos y llenar el array
- System.out.println("Lectura de los elementos del array: ");
- for (o = 0; o < 12; o++) {
- System.out.print("numeros[" + o + "]= ");
- numeros[o] = sc.nextInt();
- }
- for (int i = 0; i < numeros.length; i++) {
- for (int j = 0; j < numeros.length; j++) {
- if (numeros[i] == numeros[j]) {
- elemA++;
- }
- }
- System.out.print(numeros[o]);
- System.out.println("El elemento " + numeros[i] + " se presenta " + elemA + " veces repetido");
- elemA = 0;
- }
- for (int i = 0; i < numeros.length; i++) {
- for (int j = 0; j < numeros.length; j++) {
- if (numeros[i] == numeros[j]) {
- elemA++;
- }
- }
- System.out.println("Numeros Repetidos" +numeros[i] + elemA);
- elemA = 0;
- }
- break;
- }
- }
- }
- package palindromo;
- import java.util.Scanner;
- public class vectores {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int o;
- int elemA = 0;
- int pos = 0, neg = 0; //contadores de los números positivos y negativos
- int[] numeros = new int[10]; //array que contendrá los números leídos por teclado
- double sumaPos = 0, sumaNeg = 0; //acumuladores para las sumas de positivos y negativos
- //lectura de datos y llenar el array
- System.out.println("Lectura de los elementos del array: ");
- for (o = 0; o < 10; o++) {
- System.out.print("numeros[" + o + "]= ");
- numeros[o] = sc.nextInt();
- }
- for (int i = 0; i < numeros.length; i++) {
- for (int j = 0; j < numeros.length; j++) {
- if (numeros[i] == numeros[j]) {
- elemA++;
- }
- }
- System.out.println("El elemento " + numeros[i] + " se presenta " + elemA + " veces repetido");
- elemA = 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement