How to Get User Input with Java

To get the users input the module Scanner must be imported. Scanner is built into the java.util package and is used for retrieving inputted datatypes. Here is a link to the Scanner documentation for a more in detail explanation for the package.

import java.util.Scanner; // import the Scanner 

class aaa {
  public static void main(String[] args) {	
	  
    Scanner input = new Scanner(System.in);
    
    //Variables 
    String Name;
    String Last;
    
    // Enter first & last name
    // Press Enter after
    System.out.println("Enter First & Last Name"); 
    Name = input.nextLine();  
    Last = input.nextLine();
    System.out.println("Full Name is: " + Name + " " + Last);   
     
  }
}

Output:

Enter First & Last Name
code
it
Full Name is: code it

Its important to note that Scanner accepts different input types. For this example, notice the line input.nextLine()

nextLine() is a keyword that tells Scanner that the user is inputting a String. In the table below are a some commonly used Input types.

nextLine()
Reads a String value 
nextInt()Reads a int value
nextFloat()Reads a float value
nextDouble()Reads a double value
Commonly used user Input Types

Android Studio Loading Animation Between Activities

Progress Dialog is dialog showing a progress indicator and an optional text message or view. The methods of Progress Dialog being used in this tutorial are: ProgressDialog.setTitle() – Used to set title of dialog box ProgressDialog.setMessage() – Used to set dialog message being displayed ProgressDialog.setProgressStyle() – Choose the style of indicator ProgressDialog.dismiss() – Dismiss the … Read more Android Studio Loading Animation Between Activities

Android Studio Tutorial SeekBar

SeekBar is an extension of ProgressBar that adds a draggable thumb. The user can touch thumb and drag left or right to set the current progress level or various other task. In this example, the seekbar will be used to display a percentage. As the user moves the SeekBar left to right the percentage value … Read more Android Studio Tutorial SeekBar

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s