0
package nine.march.twenty;

import java.util.Scanner;

public class UpperCaseToLowerCase {

    public static void main(String[] args) {

        char ch='a';
        
    }
}

If I put 'a' I want 'A '

If I put 'A' I want 'a'

Spectric
  • 30,714
  • 6
  • 20
  • 43
  • Well, basically you need to invert the case. Check: https://stackoverflow.com/questions/1729778/how-can-i-invert-the-case-of-a-string-in-java – Berkay Mar 09 '21 at 15:05

1 Answers1

5

Use Character.isUpperCase() to determine what case the character is, and Character.toLowerCase() and Character.toUpperCase() to change the case.

char c = 'A';
char result = Character.isUpperCase(c) ? Character.toLowerCase(c) : Character.toUpperCase(c);
System.out.println(result);

Which prints:

a
Spectric
  • 30,714
  • 6
  • 20
  • 43
  • 2
    If you need it to be locale-sensitive, it is recommend that one use `String#toUpperCase`. – mre Mar 09 '21 at 15:16