Read floating point number user input in java

Complete source code below, will show you how to wait and read floating point number user input in command prompt.

********************************************************************
COMPLETE SOURCE CODE FOR : ReadFloatingPointNumberUserInput.java
********************************************************************


import java.util.Scanner;

public class ReadFloatingPointNumberUserInput
{
public static void main(String[]args)
{
try
{
//Create a scanner object
//Scanner is a predefined class in java that will be use to scan text
//System.in is mean, we will receive input from standard input stream
Scanner readUserInput=new Scanner(System.in);

//Print into command prompt(Put a floating point number : )
System.out.print("Put a floating point number : ");

//Wait and READ FLOATING POINT NUMBER from user input after user hit 'Enter'
float myPointNumber=readUserInput.nextFloat();

//Print what store in myPointNumber
System.out.println("My floating point number is : "+myPointNumber);
}
catch(Exception exception)
{
//Error that will be print if user put other than floating point number
System.out.println("Hey !!! Don't put other than floating point number");
}
}
}


********************************************************************
JUST COMPILE AND EXECUTE IT
********************************************************************

Read integer user input in java

Complete source code below, will show you how to wait and read integer user input in command prompt.

**********************************************************************
COMPLETE SOURCE CODE FOR : ReadIntegerUserInput.java
**********************************************************************


import java.util.Scanner;

public class ReadIntegerUserInput
{
public static void main(String[]args)
{
try
{
//Create a scanner object
//Scanner is a predefined class in java that will be use to scan text
//System.in is mean, we will receive input from standard input stream
Scanner readUserInput=new Scanner(System.in);

//Print into command prompt(What is your age ?)
System.out.println("What is your age ?");

//Wait and READ INTEGER INPUT from user after user hit 'Enter'
int myAge=readUserInput.nextInt();

//Print what store in myAge
System.out.println("Your age is : "+myAge);
}
catch(Exception exception)
{
//Error that will be print if user put other than number include
//point number
System.out.println("Hey !!! Don't put other than number");
}
}
}


**********************************************************************
JUST COMPILE AND EXECUTE IT
**********************************************************************

Read a word user input in java

Complete source code below, will show you how to wait and read only a word from user input in command prompt.

*****************************************************************
COMPLETE SOURCE CODE FOR : ReadOneWordUserInput.java
*****************************************************************


import java.util.Scanner;

public class ReadOneWordUserInput
{
public static void main(String[]args)
{
//Create a scanner object
//Scanner is a predefined class in java that will be use to scan text
//System.in is mean, we will receive input from standard input stream
Scanner readUserInput=new Scanner(System.in);

//Print into command prompt(What is your gender ?)
//Print into command prompt(Female/Male)
System.out.println("What is your gender ?\nFemale/Male");

//Wait and READ A WORD from user input after user hit 'Enter'
//Method next() in class scanner will read only first word in user input
//So, second word that seperate by space will be ignore.
String myGender=readUserInput.next();

//Print what store in myGender
System.out.println(myGender);
}
}


*****************************************************************
JUST COMPILE AND EXECUTE IT
*****************************************************************

Read text user input in java

Complete source code below, will show you how to wait and read text user input in command prompt.

********************************************************************
COMPLETE SOURCE CODE FOR : ReadTextUserInput.java
********************************************************************


import java.util.Scanner;

public class ReadTextUserInput
{
public static void main(String[]args)
{
//Create a scanner object
//Scanner is a predefined class in java that will be use to scan text
//System.in is mean, we will receive input from standard input stream
Scanner readUserInput=new Scanner(System.in);

//Print into command prompt(What is your name ?)
System.out.println("What is your name ?");

//Wait and READ TEXT INPUT from user after user hit 'Enter'
String myName=readUserInput.nextLine();

//Print what store in myName
System.out.println(myName);
}
}


********************************************************************
JUST COMPILE AND EXECUTE IT
********************************************************************

Wait user input in java

Complete source code below will show you, how to wait for user input in command prompt.
Input is a line of text.

**********************************************************************
COMPLETE SOURCE CODE FOR : WaitUserInput.java
**********************************************************************


import java.util.Scanner;

public class WaitUserInput
{
public static void main(String[]args)
{
//Create a scanner object
//Scanner is a predefined class in java that will be use to scan text
//System.in is mean, we will receive input from standard input stream
Scanner readUserInput=new Scanner(System.in);

//Print into command prompt(What is your name ?)
System.out.println("What is your name ?");

//WAIT FOR USER INPUT
//After user put it's name, he or she must press 'Enter'
//After user press 'Enter', all the input contents will read into 'myName'
String myName=readUserInput.nextLine();

//Print what it store in myName
System.out.println(myName);
}
}


**********************************************************************
JUST COMPILE AND EXECUTE IT
**********************************************************************

User input in java

Ok, now i share with you how you can handle user input in java.

>>Receive user input from command line


>>Receive user input from input box


>>Receive user input from text field

>>Receive user input from text area