Java Program To Read Data from Keyboard

Java Program To Read Data from Keyboard

Write Java Program to read data from the keyboard

// WAP to use scanner package for reading data

import java.util.Scanner;
public class ScannerClass 
    public static void main(String []args)
        int a;
        float b;
        char c;
        // object 'sc' created to scan data
        Scanner sc = new Scanner(;
        System.out.println("Enter decimal number :--> ");
        a = sc.nextInt();    // read from keyboard

        System.out.println("Enter floating point number :--> ");
        b  = sc.nextFloat();    // read from keyboard

        System.out.println("Enter character  :--> ");
        c =;    // read from keyboard
        // charAt: return 0 index character

        //displaying values stored in variables
        System.out.println("Entered decimal number :--> "+a);
        System.out.println("Entered float number :--> "+b);
        System.out.println("Entered character  :--> "+c);