fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. static String shifter(String stringToShift, int numberOfShifts){
  11. for(int i = 0; i < numberOfShifts;i++)
  12. {
  13. // Store the character you want to shift
  14. char temporaryChar = stringToShift.charAt(stringToShift.length()- i - 1);
  15.  
  16. // Store the character with the original String. Character first
  17. stringToShift = temporaryChar + stringToShift;
  18.  
  19. // Now that we did that, the string is 1 character longer so we need to take a substring of it
  20. stringToShift = stringToShift.substring(0, stringToShift.length()-1);
  21. }
  22.  
  23. // After everything is done return the String
  24. return stringToShift;
  25. }
  26.  
  27. public static void main (String[] args) throws java.lang.Exception
  28. {
  29. System.out.println(shifter("abcde", 2));
  30. }
  31. }
Success #stdin #stdout 0.04s 711168KB
stdin
Standard input is empty
stdout
ceabc