desislava_topuzakova

03. Characters in Range

Jun 12th, 2022
1,229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.40 KB | None | 0 0
  1. SoftUni Judge
  2. Contests
  3. Submissions
  4. Feedback
  5. Administration
  6. Hello, desislava.topuzakova!
  7. Log out
  8. Search
  9. Home Submissions 23088909
  10. Solution #23088909 by desislava.topuzakova for problem 03. Characters in Range
  11.  
  12. Zero test #1 (Correct answer) Run #223822102 Test #102026
  13. The zero tests are not included in the final result.
  14. Expected output:Your output:
  15. 1
  16. b c
  17. 1
  18. b c
  19. Time used: 0.045 s
  20. Memory used: 0.00 MB
  21. Zero test #2 (Correct answer) Run #223822103 Test #102027
  22. The zero tests are not included in the final result.
  23. Expected output:Your output:
  24. 1
  25. $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9
  26. 1
  27. $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9
  28. Time used: 0.070 s
  29. Memory used: 0.00 MB
  30. Zero test #3 (Correct answer) Run #223822104 Test #102028
  31. The zero tests are not included in the final result.
  32. Expected output:Your output:
  33. 1
  34. $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B
  35. 1
  36. $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B
  37. Time used: 0.073 s
  38. Memory used: 0.00 MB
  39. Test #1 (Correct answer) Run #223822105 Test #102029
  40. Expected output:Your output:
  41. 1
  42. c d e f g h i j k l m n o p q
  43. 1
  44. c d e f g h i j k l m n o p q
  45. Time used: 0.056 s
  46. Memory used: 0.00 MB
  47. Test #2 (Correct answer) Run #223822106 Test #102030
  48. Expected output:Your output:
  49. 1
  50. 2 3 4 5 6 7 8
  51. 1
  52. 2 3 4 5 6 7 8
  53. Time used: 0.069 s
  54. Memory used: 0.00 MB
  55. Test #3 (Correct answer) Run #223822107 Test #102031
  56. Expected output:Your output:
  57. 1
  58. " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @
  59. 1
  60. " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @
  61. Time used: 0.073 s
  62. Memory used: 0.00 MB
  63. Test #4 (Correct answer) Run #223822108 Test #102032
  64. Expected output:Your output:
  65. 1
  66. B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y
  67. 1
  68. B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y
  69. Time used: 0.052 s
  70. Memory used: 0.00 MB
  71. Source code
  72. 1
  73. package Methods_Exercise;
  74. 2
  75. ​
  76. 3
  77. import java.util.Scanner;
  78. 4
  79. ​
  80. 5
  81. public class CharactersInRange_03 {
  82. 6
  83.    public static void main(String[] args) {
  84. 7
  85.        Scanner scanner = new Scanner(System.in);
  86. 8
  87.        char symbol1 = scanner.nextLine().charAt(0);
  88. 9
  89.        char symbol2 = scanner.nextLine().charAt(0);
  90. 10
  91.        //метод, който отпечатва ред с всички символи от по-малкия (< аски код)
  92. 11
  93.        printSequenceOfChars(symbol1, symbol2);
  94. 12
  95.    }
  96. 13
  97. ​
  98. 14
  99.    private static void printSequenceOfChars(char symbol1, char symbol2) {
  100. 15
  101.        //проверка от кой символ да започнем
  102. 16
  103.        if (symbol1 < symbol2) {
  104. 17
  105.            //започваме от symbol1 до symbol2
  106. 18
  107.            //a до d -> b c
  108. 19
  109.            for (char symbol = (char)(symbol1 + 1); symbol < symbol2; symbol++) {
  110. 20
  111.                System.out.print(symbol + " ");
  112. 21
  113.            }
  114. 22
  115.        } else { //symbol1 >= symbol2
  116. 23
  117.            //започваме от symbol2
  118. 24
  119.            for (char symbol = (char)(symbol2 + 1); symbol < symbol1; symbol++) {
  120. 25
  121.                System.out.print(symbol + " ");
  122. 26
  123.            }
  124. 27
  125.        }
  126. 28
  127. ​
  128. 29
  129.    }
  130. 30
  131. }
  132. 31
  133. ​
  134. Created on: 08/10/2021 19:39:36
  135.  
  136. Modified on: 22/12/2021 14:19:59
  137.  
  138. © 2011-2022 - Open Judge System (OJS) 1.5.20150729.95737d0 - running on Windows. Open source project.
Advertisement
Add Comment
Please, Sign In to add comment