India's Largest Free Online Education Platform

How to take user input in java

How to take user input in java

Program code:

import java.util.Scanner;
public class input_operator {
    public static void main(String args[])
    {
        Scanner Sc = new Scanner(System.in);
        System.out.println("Enter an integer value");
        int a = Sc.nextInt();
        System.out.println("You entered: " + a);

        System.out.println("Enter a float value");
        float b = Sc.nextFloat();
        System.out.println("You entered: " + b);

        System.out.println("Enter your first name");
        String c = Sc.next();
        System.out.println("You entered: " + c);
    }
}

Output:

Leave a Reply

Your email address will not be published. Required fields are marked *

error: Content is protected !!