desislava_topuzakova

03. Characters in Range

Feb 7th, 2021
669
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.76 KB | None | 0 0
  1. import java.util.Locale;
  2. import java.util.Scanner;
  3.  
  4. public class ProjectsCreation {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.         char startSymbol = scanner.nextLine().charAt(0);
  8.         char endSymbol = scanner.next().charAt(0);
  9.  
  10.         printSymbolsInRange(startSymbol, endSymbol);
  11.  
  12.     }
  13.  
  14.     static void printSymbolsInRange(char start, char end) {
  15.         if(start < end) {
  16.             for (int ascii = start + 1; ascii <= end - 1; ascii++) {
  17.                 System.out.print((char) ascii + " ");
  18.             }
  19.         } else {
  20.             for (int ascii = end + 1; ascii <= start - 1; ascii++) {
  21.                 System.out.print((char) ascii + " ");
  22.             }
  23.         }
  24.     }
  25.  
  26.  
  27.  
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment