Re: Java Help for a begginer
Quote:
display on the same window
Build one String with all the lines to be displayed separated by newline characters: (\n) and display that.
Re: Java Help for a begginer
Thank you so much. now how do i get it to obtain the name and color in one window? if i do it like the output then it will use both of them for %s and i want two different answers.
Current code:
Code java:
import javax.swing.JOptionPane;
public class gui{
public static void main(String[] args) {
String name=
JOptionPane.showInputDialog("What is your name?");
String names=
JOptionPane.showInputDialog("What is your favorite color?");
String mess =
String.format("Your name is %s \nYour Favorite color is %s", name, names);
JOptionPane.showMessageDialog(null, mess);
}
}
Re: Java Help for a begginer
Quote:
how do i get it to obtain the name and color in one window?
Have the user enter all the values you want on one line before pressing Enter.
You'll have to separate them after the method returns them into a String.