SophiYo

CharsBetweenTwo

Feb 14th, 2019
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.21 KB | None | 0 0
  1. package O4MethodsAndFunctions;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6.  
  7. public class Ex03CharactersInRange {
  8.     public static void main(String[] args) throws IOException {
  9.         BufferedReader reader = new BufferedReader
  10.                 (new InputStreamReader(System.in));
  11.  
  12.         char first = reader.readLine().charAt(0);
  13.         char second = reader.readLine().charAt(0);
  14.  
  15.         int i = 0;
  16.         char symbol = '\u0000';
  17.         printCharsBetweenFirstAndSecond(first, second, i );
  18.     }
  19.     static void printCharsBetweenFirstAndSecond(char first, char second, int i) {
  20.  
  21.         if (first > second) {
  22.             for (i = first + 1; i < second; i++) {
  23.                 if (i == second-1) {
  24.                     System.out.print((char) i + " ");
  25.                 } else {
  26.                     System.out.print(((char) i));
  27.                 }
  28.             }
  29.         } else {
  30.             for (i = second + 1; i < first; i++) {
  31.                 if (i == first-1) {
  32.                     System.out.print((char) i + " ");
  33.                 } else {
  34.                     System.out.print(((char) i));
  35.                 }
  36.             }
  37.         }
  38.  
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment