Advertisement
Juan_Del_Rio

Untitled

Mar 31st, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package ent.utils;
  7.  
  8. import java.util.Scanner;
  9.  
  10. /**
  11. *
  12. * @author JUAN
  13. */
  14. public class Util {
  15.  
  16. public static String cfr(String inp, int n) {
  17. String abc = "abcdefghijklmnopqrstuvwxyz";
  18. char cif, sinCif;
  19. int posiAbc, posiCif;
  20. String out = "", aux;
  21. boolean may;
  22.  
  23. for (int i = 0; i < inp.length(); i++) {
  24. may = false;
  25. sinCif = inp.charAt(i);
  26. if (Character.isUpperCase(sinCif)) {
  27. sinCif = Character.toLowerCase(sinCif);
  28. may = true;
  29. }
  30. posiAbc = abc.indexOf(sinCif);
  31. if (posiAbc == -1) {
  32. cif = sinCif;
  33. } else {
  34. posiCif = posiAbc + n;
  35. if (posiCif > 25) {
  36. posiCif = posiCif % 26;
  37. } else if (posiCif < 0) {
  38. posiCif = posiCif + 26;
  39. }
  40. cif = abc.charAt(posiCif);
  41. }
  42. if (may == true) {
  43. aux = String.valueOf(cif).toUpperCase();
  44. } else {
  45. aux = String.valueOf(cif);
  46. }
  47. out = out + aux;
  48. }
  49.  
  50. return out;
  51. }
  52.  
  53. public static int sacarDesplazamiento(Scanner scFile, String abc) {
  54. int desp = 0, n, max = -1, posi = 0;
  55. int[] ia = new int[26];
  56. String linea;
  57. char l;
  58.  
  59. while (scFile.hasNextLine()) {
  60. linea = scFile.nextLine().toLowerCase();
  61. for (int i = 0; i < linea.length(); i++) {
  62. l = linea.charAt(i);
  63. n = abc.indexOf(l);
  64. if (n != -1) {
  65. ia[n]++;
  66. }
  67.  
  68. }
  69.  
  70. }
  71.  
  72. for (int i = 0; i < ia.length; i++) {
  73. if (ia[i] > max) {
  74. max = ia[i];
  75. posi = i;
  76. }
  77. }
  78.  
  79. desp = 4 - posi;
  80.  
  81. return desp;
  82. }
  83.  
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement