Input an alphabet and change its case

Input an alphabet and change its case

Previous Home Next

 

Input an alphabet and change its case

 

 //Program for Case(Lower to higher)
package r4r.co.in;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class LowerToHigher {

    public static void main(String[] args) throws IOException {

        BufferedReader D1 = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Enter the word A:");
        String s1 = D1.readLine();


        //Code for Case(Lower to higher)

        char n1 = (char) s1.getBytes()[0];    //type conversion
        if (n1 >= 'a' && n1 <= 'z') {        //Define region(a to z)
            s1 = s1.toUpperCase();


            System.out.println("Change to Uppercase:" + s1);
        } else if (n1 >= 'A' && n1 <= 'Z') {
            s1 = s1.toLowerCase();
            System.out.println("Change to Lowercase:" + s1);

        }
    }
}

Enter the word A:
H
Change to Lowercase:h

or

Enter the word A:
f
Change to Uppercase:F

Previous Home Next