Advertisement
Guest User

Untitled

a guest
Nov 15th, 2015
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Keyboard {
  4.  
  5. public static void main(String[] args) {
  6. Scanner scanner =new Scanner (System.in);
  7. String dir=scanner.nextLine();
  8. String text=scanner.nextLine();
  9.  
  10. String s1="qwertyuiop";
  11. String s2="asdfghjkl;";
  12. String s3="zxcvbnm,./";
  13.  
  14. int t;
  15.  
  16. StringBuilder sb=new StringBuilder();
  17.  
  18. for(int i=0;i<text.length();i++){
  19. if(dir.equals("R"))
  20. {
  21. if(s1.contains(""+text.charAt(i)))
  22. {
  23. t=s1.indexOf(text.charAt(i));if(t<0 || t>=s1.length()){sb.append(text.charAt(i));continue;}
  24. sb.append(s1.charAt((s1.indexOf(text.charAt(i)))-1));
  25. }
  26. else if(s2.contains(""+text.charAt(i)))
  27. {
  28. t=s2.indexOf(text.charAt(i));if(t<0 || t>=s2.length()){sb.append(text.charAt(i));continue;}
  29. sb.append(s2.charAt((s2.indexOf(text.charAt(i)))-1));
  30. }
  31.  
  32. else if(s3.contains(""+text.charAt(i)))
  33. {
  34. t=s3.indexOf(text.charAt(i));if(t<0 || t>=s3.length()){sb.append(text.charAt(i));continue;}
  35. sb.append(s3.charAt((s3.indexOf(text.charAt(i)))-1));
  36.  
  37. }
  38. }
  39.  
  40. else if (dir.equals("L"))
  41. {
  42. if(s1.contains(""+text.charAt(i)))
  43. {
  44. t=s1.indexOf(text.charAt(i));if(t<0 || t>=s1.length()){sb.append(text.charAt(i));continue;}
  45. sb.append(s1.charAt((s1.indexOf(text.charAt(i)))+1));
  46. }
  47.  
  48.  
  49. else if(s2.contains(""+text.charAt(i)))
  50. {
  51. t=s2.indexOf(text.charAt(i));if(t<0 || t>=s2.length()){sb.append(text.charAt(i));continue;}
  52. sb.append(s2.charAt((s2.indexOf(text.charAt(i)))+1));
  53. }
  54.  
  55.  
  56. else if(s3.contains(""+text.charAt(i)))
  57. {
  58. t=s3.indexOf(text.charAt(i));if(t<0 || t>=s3.length()){sb.append(text.charAt(i));continue;}
  59. sb.append(s3.charAt((s3.indexOf(text.charAt(i)))+1));
  60. }
  61. }
  62.  
  63. } // END OF FOR LOOP
  64.  
  65. System.out.println(sb.toString());
  66. scanner.close();
  67. }
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement