Getting Started with Java: Getting user input for the underlying algorithm

Source: Internet
Author: User
Tags float number

This section shows how to get user input. We use the scanner class to get user input. The following example code shows how to get the string, integer, and float data entered by the user. The main use of the following methods:

1) public string nextline (): Gets the input string

2) public int nextint (): Gets the integer entered

3) public float nextfloat (): Gets the input float number

Import java.util.scanner;class getinputdata{public static void Main (String args[]) {intnum; floatFnum;      String str; Scannerinch= new Scanner (System.inch); //Get Input StringSystem.out.println ("Enter A string:"); STR=inch. nextline (); System.out.println ("Input String is:"+str); //Get Input IntegerSystem.out.println ("Enter an integer:"); Num=inch. Nextint (); System.out.println ("Input Integer is:"+num); //Get Input Float numberSystem.out.println ("Enter A float number:"); Fnum=inch. Nextfloat (); System.out.println ("Input Float number is:"+fnum); }}

Getting Started with Java: Getting user input for the underlying algorithm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.