Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

how to take user input in java

+3 votes
asked Sep 3 by Mohit shakya (150 points)

5 Answers

+1 vote
answered Sep 4 by Peter Minarik (78,090 points)

Use the Scanner class as shown in this article.

+2 votes
answered Sep 7 by MD FAIZAN ANWAR (180 points)
edited Sep 8 by MD FAIZAN ANWAR
import java.util.*;

class Array


public static void main(String args[]){

    Scanner sc=new Scanner(System.in);

      int n =sc.nextInt();



+1 vote
answered Sep 16 by 218A1A05B8 NUSUM SASI PREETHAM (560 points)
we use Scanner class to take user input in java as shown below example

incase text files we use BufferReader class  to take input from user

import java.util.*;

class InputByUser {

    public static void main(String[] args) {

        Scanner sc =new Scanner(System.in);

        int a=sc.nextInt();//for integer

        double b=sc.nextDouble();//for floating values


+1 vote
answered Sep 17 by SURAJ PRATAP SINGH (160 points)
//For take input from user


class Input


     public static void main(String args[])


             Scanner obj = new Scanner(System.in)

                 int n;


                  System.out.println("User Inputting Number is "+n);


0 votes
answered 1 day ago by Shreyash Singh (140 points)
Scanner sc=new Scanner (System.in);

int a=sc.next Int();
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.