Java programming read input format output from console and from inputbox

Publié le: 26 octobre 2020
sur la chaîne: RioProfessor Liu
764
2

Using dialog box for Input and Output

Using Console output windows to prompt for Input and output is very old-fashioned . And sometimes outdated. The more current way is to create a separate pop-up windows for each input.



Call the static showInputDialog method of the JOptionPane class, and supply the string that prompts the input from the user. For example:

Read an Integer

String strNumber= JOptionPane.showInputDialog("Enter an integer number:");

The above method returns a String object.

Use the Integer.parseInt(strNumber) to convert the strNumber to an Integer intNumber

int intNumber = Integer.parseInt(strNumber) ;



Read a number with decimal points.

String strPrice= JOptionPane.showInputDialog("Enter a price:");

The above method returns a String object.

Use the Double.parseDouble(strPrice) to convert the strPrice to a double number dblPrice

double dblPrice = Double.parseDouble(strPrice) ;

Display on a messgebox

JOptionPane.showMessageDialog(null, "Price : " + price);


Sur cette page du site, vous pouvez voir la vidéo en ligne Java programming read input format output from console and from inputbox durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur RioProfessor Liu 26 octobre 2020, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 764 fois et il a aimé 2 téléspectateurs. Bon visionnage!