Advertisement
ppathak35

togglecase

Jun 24th, 2022
724
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.43 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Main {
  4.     public static void main(String[] args)
  5.     {
  6.         Scanner sc = new Scanner(System.in);
  7.         String str = "Hello WorlD";
  8.         int choice = 1;
  9.         char[] arr= str.toCharArray();
  10.        
  11.         while (choice != 4) {
  12.             System.out.println("1. Uppercase");
  13.             System.out.println("2. Lowercase");
  14.             System.out.println("3. ToggleCase");
  15.             System.out.println("4. Exit");
  16.            
  17.             System.out.print("\nEnter your choice : ");
  18.             choice = sc.nextInt();
  19.            
  20.             if (choice == 1) {
  21.                 System.out.println("Upper : " + str.toUpperCase());
  22.             }
  23.             else if (choice == 2) {
  24.                 System.out.println("Lower : " + str.toLowerCase());
  25.             }
  26.             else if (choice == 3) {
  27.                 System.out.print("Toggle : ");
  28.                 for (char ch : arr) {
  29.                     if(Character.isUpperCase(ch)){
  30.                         ch= Character.toLowerCase(ch);
  31.                     }
  32.                     else if(Character.isLowerCase(ch)){
  33.                         ch= Character.toUpperCase(ch);
  34.                     }
  35.                     System.out.print(ch);
  36.                 }
  37.             }
  38.             else if (choice == 4) {
  39.                 System.out.println("Program Terminated");
  40.             }
  41.             System.out.println();
  42.         }
  43.     }
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement