Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package ent.utils;
- import java.util.Scanner;
- /**
- *
- * @author JUAN
- */
- public class Util {
- public static String cfr(String inp, int n) {
- String abc = "abcdefghijklmnopqrstuvwxyz";
- char cif, sinCif;
- int posiAbc, posiCif;
- String out = "", aux;
- boolean may;
- for (int i = 0; i < inp.length(); i++) {
- may = false;
- sinCif = inp.charAt(i);
- if (Character.isUpperCase(sinCif)) {
- sinCif = Character.toLowerCase(sinCif);
- may = true;
- }
- posiAbc = abc.indexOf(sinCif);
- if (posiAbc == -1) {
- cif = sinCif;
- } else {
- posiCif = posiAbc + n;
- if (posiCif > 25) {
- posiCif = posiCif % 26;
- } else if (posiCif < 0) {
- posiCif = posiCif + 26;
- }
- cif = abc.charAt(posiCif);
- }
- if (may == true) {
- aux = String.valueOf(cif).toUpperCase();
- } else {
- aux = String.valueOf(cif);
- }
- out = out + aux;
- }
- return out;
- }
- public static int sacarDesplazamiento(Scanner scFile, String abc) {
- int desp = 0, n, max = -1, posi = 0;
- int[] ia = new int[26];
- String linea;
- char l;
- while (scFile.hasNextLine()) {
- linea = scFile.nextLine().toLowerCase();
- for (int i = 0; i < linea.length(); i++) {
- l = linea.charAt(i);
- n = abc.indexOf(l);
- if (n != -1) {
- ia[n]++;
- }
- }
- }
- for (int i = 0; i < ia.length; i++) {
- if (ia[i] > max) {
- max = ia[i];
- posi = i;
- }
- }
- desp = 4 - posi;
- return desp;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement