Java Program to Get Input From User

You are currently viewing Java Program to Get Input From User

Java program to get input from user

//program to input int, float and string value
import java.util.Scanner;
 
public class GetIpAddress
{
    public static void main(String args[])  throws Exception
    {
        String name, gender;
        int age;
        float weight;
         
        Scanner SC=new Scanner(System.in);
         
        System.out.print("Enter name: ");
        name= SC.nextLine();
         
        System.out.print("Enter Gender (Male/Female): ");
        gender=SC.next();
 
        System.out.print("Enter age: ");
        age=SC.nextInt();
 
        System.out.print("Enter weight: ");
        weight=SC.nextFloat();
         
        System.out.println("Name: " + name);
        System.out.println("Gender: " + gender);
        System.out.println("Age: " + age);
        System.out.println("Weight: " + weight);
                                  
    }
}

Output

    Enter name: Mike the Expert
    Enter Gender (Male/Female): Male
    Enter age: 21
    Enter weight: 65.50
    Name: Mike the Expert
    Gender: Male
    Age: 21
    Weight: 65.5

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply