Java basic programming structure (3)

Source: Internet
Author: User
(7) read input
/*
* To change this template, choose tools | templates
* And open the template in the editor.
*/

Package readinput;

Import javax. Swing. joptionpane;

/**
*
* @ Author Vanessa
*/
Public class main {

/**
* @ Param ARGs the command line arguments
*/
Public static void main (string [] ARGs ){
// Todo code application logic here
// Get first input
String name = joptionpane. showinputdialog
("What is your name? ");

// Get second input
String input = joptionpane. showinputdialog
("How old are you? ");

// Convert string to integer value
Int age = integer. parseint (input );

// Display output on Console
System. Out. println ("hello," + name +
". Next year, you'll be" + (age + 1 ));

System. Exit (0 );
}

}
 

2. format the output.
Numberformat. getcurrencyinstance ()
Numberformat. getpercentinstance ()
Numberformat. getnumberinstance ()

Static numberformat getcurrencyinstance ()
// Returns a numberformat object to convert currency values to strings using the conventions of the current locale.

Static numberformat getnumberinstance ()
// Returns a numberformat object to format numbers using the conventions of the current locale.

Static numberformat getpercentinstance ()
// Returns a numberformat object to convert percentages to strings.

String format (double number)
// Returns a string that contains the formatted number.

Void setmaximumfractiondigits (INT digits)
// Parameters:
// Digits: the number of digits to display
// Sets the maximum number of digits after the decimal point for the format object. The last
// Displayed digit is rounded.

Void setmaximumintegerdigits (INT digits)
// Parameters:
// Digits: the number of digits to display
// Sets the maximum number of digits before the decimal point for the format object. use this method with extreme caution. if you specify too few digits, then the number is simply truncated, displaying a dramatically wrong result!

Void setminimumfractiondigits (INT digits)
// Parameters:
// Digits: the number of digits to display
// Sets the minimum number of digits after the decimal point for the format object. If the number has fewer fractional digits than the minimum, then Trailing zeroes are supplied.

Void setminimumintegerdigits (INT digits)
// Parameters:
// Digits: the number of digits to display
// Sets the minimum number of digits before the decimal point for the format object. If the number has fewer digits than the minimum, then leading zeroes are supplied.

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.