Taking input from the user

Created by Piyush Garg about a year ago


No description provided



    Takeaway points :

    1. we need to import scanner class by import java.util.Scanner ;
    2. then Scanner sc = new Scanner ( ;
    3. and then according to the type of input like int , float , boolean u have to use different methods of scanner class int a = sc.nextInt() float b = sc.nextFloat(); String name =; // somehow nextLine is not working but have to research why it is not working .

    ravi karthik



    Note:- When sc.nextInt() is called in Java, it only reads the integer value and not the newline character that is entered after it. Therefore, when sc.nextLine() is called after sc.nextInt(), it reads the newline character left by the previous call to sc.nextInt(), resulting in an empty string being returned. To avoid this issue, you can add an extra sc.nextLine() call after sc.nextInt() to consume the newline character before calling sc.nextLine() again to read the next line of input.


    Day 3: Finally i got to learn how to take input in JAVA. so we import a Scanner class and use its methods for the input of different data types nextInt() --> integer next() --> string nextFloat() --> float


    Himanshu Kandpal


Your comment