vittooh

Fatorial correto

Dec 10th, 2014
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.49 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.List;
  3. import java.util.Scanner;
  4.  
  5. /**
  6.  * Created by Vitor Hugo on 13/08/2016.
  7.  */
  8. public class Cesar {
  9.     public static void main(String[] args) {
  10.         int casos;
  11.         List<String> toCript = new ArrayList<>();
  12.         List<Integer> junpCript = new ArrayList<>();
  13.         List<String> cript = new ArrayList<>();
  14.         Scanner sc = new Scanner(System.in);
  15.         casos = Integer.parseInt(sc.nextLine());
  16.         while (casos != 0) {
  17.             sc.reset();
  18.             toCript.add(sc.nextLine());
  19.             junpCript.add(Integer.valueOf(sc.nextLine()));
  20.             casos--;
  21.         }
  22.  
  23.         for (String frase : toCript) {
  24.             int junp = junpCript.get(toCript.indexOf(frase));
  25.             char[] currentFrase = frase.toCharArray();
  26.             for (int i = 0; i < currentFrase.length; i++) {
  27.                 int valueAscii = currentFrase[i];
  28.                 if(valueAscii - junp >=65){
  29.                     currentFrase[i] = (char) (valueAscii - junp);
  30.                 }else{
  31.                     valueAscii = (valueAscii - 65);
  32.                     valueAscii =Math.abs(valueAscii -junp);
  33.                     valueAscii  = 90 - valueAscii +1 ;
  34.                     currentFrase[i] = (char) valueAscii;
  35.                 }
  36.             }
  37.             cript.add(String.valueOf(currentFrase));
  38.         }
  39.         for (String frase: cript) {
  40.             System.out.println(frase);
  41.         }
  42.         System.out.println();
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment