Advertisement
andkamen

no error

Mar 4th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. package com.Olympiad2016;
  2.  
  3. import java.util.Scanner;
  4. public class t {
  5.  
  6.  
  7. public static void main(String[] args) {
  8. Scanner sc = new Scanner(System.in);
  9. while (true){
  10. String commandLine = sc.nextLine();
  11. if (commandLine.equals("start") || commandLine.equals("START")){
  12. break;
  13. }
  14. }
  15. int msgCounter = 0;
  16. StringBuilder decryptMsg = new StringBuilder();
  17.  
  18. while (true) {
  19. String commandLine = sc.nextLine();
  20.  
  21. if (commandLine.equals("end")|| commandLine.equals("END")) {
  22. break;
  23. }
  24.  
  25. if (commandLine.equals("")) {
  26. continue;
  27. }
  28. msgCounter++;
  29.  
  30. for (int index = commandLine.length() - 1; index >= 0; index--) {
  31. char currentSymbol = commandLine.charAt(index);
  32.  
  33. boolean isFromAtoMLower = commandLine.charAt(index) >= 'a' && commandLine.charAt(index) <= 'm';
  34. boolean isFromAtoMUpper = commandLine.charAt(index) >= 'A' && commandLine.charAt(index) <= 'M';
  35. boolean isFromNtoZLower = commandLine.charAt(index) >= 'n' && commandLine.charAt(index) <= 'z';
  36. boolean isFromNtoZUpper = commandLine.charAt(index) >= 'N' && commandLine.charAt(index) <= 'Z';
  37. boolean isDigit = commandLine.charAt(index) >= '0' && commandLine.charAt(index) <= '9';
  38.  
  39. if (isFromAtoMUpper || isFromAtoMLower) {
  40. decryptMsg.append((char) (commandLine.charAt(index) + 13));
  41. } else if (isFromNtoZUpper || isFromNtoZLower) {
  42. decryptMsg.append((char) (commandLine.charAt(index) - 13));
  43. } else if (isDigit) {
  44. decryptMsg.append(commandLine.charAt(index));
  45. } else {
  46. switch (currentSymbol) {
  47. case '+':
  48. decryptMsg.append(' ');
  49. break;
  50. case '%':
  51. decryptMsg.append(',');
  52. break;
  53. case '&':
  54. decryptMsg.append('.');
  55. break;
  56. case '#':
  57. decryptMsg.append('?');
  58. break;
  59. case '$':
  60. decryptMsg.append('!');
  61. break;
  62. }
  63. }
  64. }
  65. }
  66.  
  67. if (msgCounter == 0){
  68. System.out.println("No messages sent.");
  69. }else {
  70. System.out.printf("Total number of messages: %d\n",msgCounter);
  71. System.out.println(decryptMsg.toString());
  72. }
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement