Java Program to character input using the Scanner class


In this program, You will learn how to character input using the Scanner class in Java.


char ch = sc.next().charAt(0);


Example: How to character input using the Scanner class in Java

Run it Now
import java.util.Scanner;

class Main {
    public static void main(String args[]) {

        char ch;
        Scanner sc = new Scanner(System.in);

        System.out.print("Enter a Character Value :");
        ch = sc.next().charAt(0);

        System.out.println("\nInput Character is :" + ch);

    }
}

Output:

Enter a Character Value :H
Input Character is :H