codedamn

Taking input from the user

Created by Piyush Garg about a year ago

0

No description provided

3 Comments

    1

    Takeaway points :

    1. we need to import scanner class by import java.util.Scanner ;
    2. then Scanner sc = new Scanner (System.in) ;
    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 = sc.next(); // somehow nextLine is not working but have to research why it is not working .
    @ravkk

    ravi karthik

    @ravkk

    5

    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.

    1

    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

    @himansys

    Himanshu Kandpal

    @himansys

Your comment