fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.util.stream.*;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. System.out.println(caesarCipher("test", 3));
  14. }
  15.  
  16. public static String caesarCipher(String cipher, int shiftAmount) {
  17. return cipher.chars()
  18. .mapToObj(c -> "" + shift((char)c, shiftAmount))
  19. .collect(Collectors.joining());
  20. }
  21.  
  22. private static char shift(char c, int amount) {
  23. char a = Character.isUpperCase(c) ? 'A' : 'a';
  24. return (char)((c - a + amount % 26 + 26) % 26 + a);
  25. }
  26. }
Success #stdin #stdout 0.12s 51204KB
stdin
Standard input is empty
stdout
whvw