Whenever Program needs input from the user we use
Syntax: -
import java.util.Scanner;

Scanner object_name = new Scanner (System.in);
Variable_name = object_name.nextInt( );
Variable_name = object_name.nextFloat( );
Variable_name = object_name.nextLine( );

Where java is package
util is sub-package
Scanner is class
nextInt ( ) nextFloat( ) nextLine( ) are Methods of Scanner class.

Example: -

import java.util.Scanner;
class Geekyshows
    public static void main (String args[])
        String word;
        int a;
        float b;
        Scanner obj = new Scanner(System.in);
        System.out.println("Enter String: ");
        word = obj.nextLine();
        System.out.println("Your have Entered a String: "+word);
        System.out.println("Enter Integer: ");
        a = obj.nextInt();
        System.out.println("Your have Entered Integer: "+a);
        System.out.println("Enter Float: ");
        b = obj.nextFloat();
        System.out.println("Your have Entered a Float: "+b);

Post a Comment

Comment Rules :
1. Do not post Adult/illegal Links.
2. Try to comment in only English Language.
3. Do not post other website's links which are useless.
4. Your Comment should be based on the Topic for other queries Kindly Visit our Contact Us Page.
5. Do not use Abusive Language.
6. Respect each other.
Thank You for following the rules. Please Comment....