Advertisement
Spocoman

08. Lower or Upper

Oct 17th, 2024
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.41 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. class Main {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int x = scanner.next().charAt(0);
  7.            
  8.         if (x > 64 && x < 91) {
  9.             System.out.println("upper-case");
  10.         } else if (x > 96 && x < 123) {
  11.             System.out.println("lower-case");
  12.         }
  13.     }
  14. }
  15.  
  16. Solutions with methods:
  17.  
  18. import java.util.Scanner;
  19.  
  20. class Main {
  21.     public static void main(String[] args) {
  22.         Scanner scanner = new Scanner(System.in);
  23.         char x = scanner.nextLine().charAt(0);
  24.            
  25.         if (Character.isUpperCase(x)) {
  26.             System.out.println("upper-case");
  27.         } else if (Character.isLowerCase(x)) {
  28.             System.out.println("lower-case");
  29.         }
  30.     }
  31. }
  32.  
  33. Solution with methods and ternary operator:
  34.  
  35. import java.util.Scanner;
  36.  
  37. class Main {
  38.     public static void main(String[] args) {
  39.         Scanner scanner = new Scanner(System.in);
  40.         char x = scanner.nextLine().charAt(0);
  41.            
  42.         System.out.println(Character.isUpperCase(x) ? "upper-case": "lower-case");
  43.     }
  44. }
  45.  
  46. Or:
  47.  
  48. import java.util.Scanner;
  49.  
  50. class Main {
  51.     public static void main(String[] args) {
  52.         Scanner scanner = new Scanner(System.in);
  53.        
  54.         System.out.println(Character.isUpperCase(scanner.nextLine().charAt(0)) ? "upper-case": "lower-case");
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement