Re: question code of java
mak wrote:
Hi , how are you , i need your help !I wrote a java application and it
appears an error such as
'cannot find symbol class format '.
The code is :
//NameDialog.java
//Basic input with a dialog box
import javax.swing.JOptionPane;
public class NameDialog{
public static void main(String[] args){
//prompt user to enter name
String name=JOptionPane.showInputDialog("What is your name?");
//create the message
String message=new String.format("Welcome,%s,to Java
programming",name);
You appear to be confusing two different things: a constructor and a
static method.
new String();
String.format(format, args);
Try omitting the "new"
String message=String.format(
"Welcome,%s,to Java programming", name);
//display the message to welcome the user by name
JOptionPane.showMessageDialog(null,message);
}//end main
}//end class NameDialog
Could you give me your valuable help please ?I will appreciate it very
much!