Você está na página 1de 5

public static boolean ePalindroma(String frase, boolean sensivelCaso, boolean mantemEspacos) { 01 if (!

mantemEspacos) { 02 String aux = ""; 03 for (int c = 0; c < frase.length(); c++) 04 if (frase.charAt(c) != ' ') 05 aux = aux + frase.charAt(c); 06 frase = aux; 06 } 07 if (!sensivelCaso) 08 frase = frase.toUpperCase(); 09 String frase2 = ""; 10 for (int i = frase.length() - 1; i >= 0; i--) 11 frase2 = frase2 + frase.charAt(i); 12 if (frase.equals(frase2)) 13 return true; else 14 return false; 15}

public static int buscaLinear(int[] vetor, int procurado) { 00 int i; 00 for (i = 0; i < vetor.length; i++) { 00 if (vetor[i] == procurado) 00 return i; 00 } 00 return -1; 00}

public static int buscaLinear2(int[] vetor, int procurado) { 00 int i; 00 for (i = 0; i < vetor.length; i++) { 00 if (vetor[i] == procurado) { 00 if (i > 0 && vetor[i] > vetor[i 1]) 00 System.out.println("Nmero removido maior que o anterior"); 00 return i; 00 } 00 } 00 return -1; 00}

public static int[] converteInteirosAbsolutos(String[] numeros, int padrao) { 00 int[] retorno = new int[numeros.length]; 00 for (int c = 0; c < numeros.length; c++) { 00 try { 00 retorno[c] = Integer.parseInt(numeros[c]); 00 } catch (NumberFormatException E) { 00 retorno[c] = padrao; 00 } 00 if (retorno[c] < 0) 00 retorno[c] *= -1; 00 } 00 return (retorno); 00}

public static void preencheVetor(int tam) { 00 int vet[] = new int[tam]; 00 float media = (float) 0.0; 00 int maior = Integer.MIN_VALUE, menor = Integer.MAX_VALUE; 00 int pares = 0, impares = 0; 00 for (int i = 0; i < tam; i++) { 00 int r0 = 50, r1=90; 00 vet[i] = (int)(Math.random() * (r1 - r0 + 1)) + r0; 00 System.out.println("Vetor[" + i + "] = " + vet[i]); 00 media += vet[i]; 00 if (vet[i] > maior) 00 maior = vet[i]; 00 if (vet[i] < menor) 00 menor = vet[i]; 00 if (vet[i] % 2 == 0) 00 pares++; 00 else 00 impares++; 00 } 00 media = media / tam; 00 System.out.println("Mdia = " + media); 00 System.out.println("Maior = " + maior + "\nMenor = " + menor); 00 System.out.println("Pares = " + pares + "\nmpares = " + impares); 00}

Você também pode gostar