Q:

formatting number JOptionPane

Good day, i'm facing the following problem. i'm generating a random number which i need to display all along some text on a JOptionPane. if i were to use a JLabel, i could have just added the JLabel to the JOptionPane straight forward. but i don't wanna make use of it. and i'm using the html tags, rather.
My question is the following, how will i get %d to get the number that i'm generating to be displayed?
with programming languages like java, i can print by doing:
System.out.printf("%d", +number);

System.out.printf(%d +number);

How will i go about with html, from the bellow code?
int number = 20140000+ generator.nextInt(999);

String msg = "<html><h3><b>You have been successfully registered into MYCARE.<br><br>Your Patient ID is: %d. Please use it to login.</br></br></b></h3></html>" +number;
JOptionPane.showMessageDialog(null, msg, "INFORMATION", JOptionPane.INFORMATION_MESSAGE);

Any help will be gladly appreciated.

A:

In your code you just concatenate number and string. Try String.format():
String msg = String.format("<html><h3><b>You have been successfully registered into MYCARE.<br><br>Your Patient ID is: %d. Please use it to login.</br></br></b></h3></html>", number);

