JOptionPane.showMessageDialog 如何显示多结果

来源:百度知道 编辑:UC知道 时间:2024/05/31 17:54:06
import javax.swing.JOptionPane;
public class E
{
public static void main(String arg[])
{
String s= JOptionPane.showInputDialog("输入一个整数:");
int n = Integer.parseInt(s);
int nn = n*n;
int nnn = nn*n;
int nnnn = nnn*n;

JOptionPane.showMessageDialog(
null,
s +"的平方:"+ nn
\ns +"的立方:" + nnn
\ns +"的四次方:" + nnnn,

"答案为",JOptionPane.PLAIN_MESSAGE);
System.exit(0);
}
}

java 程序如上,为什么显示错误,而若果 删去
\ns +"的立方:" + nnn
\ns +"的四次方:" + nnnn,

又能运行。
请高手指点,谢谢!!

public static void main(String[] args) {
String s= JOptionPane.showInputDialog("输入一个整数:");
int n = Integer.parseInt(s);
int nn = n*n;
int nnn = nn*n;
int nnnn = nnn*n;

JOptionPane.showMessageDialog(
null,
s +"的平方:"+ nn
+"\n"+s +"的立方:" + nnn
+"\n"+s +"的四次方:" + nnnn,

"答案为",JOptionPane.PLAIN_MESSAGE);
System.exit(0);
}