Java User Input In Hindi

📔 : Java 🔗

Java programming language में आप user input data को भी handle कर सकते हैं , user द्वारा enter किये गए data को handle करने के लिए java.util package की Scanner class का use किया जाता है।

Java User Input Example

File :

CopyFullscreenClose FullscreenRun
// import the Scanner class from util package.
import java.util.Scanner; 

public class UserInput {
  public static void main(String[] args) {
    Scanner scan = new Scanner(;
    String name;
    // Enter your name and press Enter.
    System.out.println("Enter name : "); 
    name = scan.nextLine();   
    System.out.println("Your name is : " + name);        
Enter name : Rahul
Your name is : Rahul

ऊपर दिए गए example में हमने , nextLine() method का use किया है जो input की गयी string line को read करता है। अलग अलग type के according scanner class में अलग - अलग methods हैं -

Java Scanner class methods
nextBoolean()to read a boolean value from input.
nextByte()to read a byte value from input.
nextDouble()to read a double value from input.
nextFloat()to read a float value from input.
nextInt()to read a int value from input.
nextLine()to read a String value from input.
nextLong()to read a long value from input.
nextShort()to read a short value from input.

अब एक example देखते हैं जिसमे हम user से अलग अलग type का input handle करेंगे -

File :

CopyFullscreenClose FullscreenRun
import java.util.Scanner;

public class Student {
  public static void main(String[] args) {
    Scanner scan = new Scanner(;
    // String input.
    System.out.println("Student name :");
    String name = scan.nextLine();
    // Integer input.
    System.out.println("Student age :");
    int age = scan.nextInt();
    // double input.
    System.out.println("Student salery :");
    double salary = scan.nextDouble();

    // Output.
    System.out.println("Name : " + name);
    System.out.println("Age : " + age);
    System.out.println("Salary : " + salary);
Student name :Ravi
Student age :
Student salery :
Name : Ravi
Age : 23
Salary : 67.56l

ध्यान रहे , जिस type की value के लिए method use कर रहे हैं input की जाने वाली value भी उसी type की हो otherwise InputMismatchException exception आएगी।

Related Topics :

Rahul Kumar

Rahul Kumar

Hi ! My name is Rahul Kumar Rajput. I'm a back end web developer and founder of I live in Uttar Pradesh (UP), India and I love to talk about programming as well as writing technical tutorials and tips that can help to others.

Get connected with me. :) LinkedIn Twitter Instagram Facebook