Java 我的计算需要和作业输入,而不是system.output
我想做的是让“for”有一个用于该计算的joption输入,而不是系统输入Java 我的计算需要和作业输入,而不是system.output,java,input,Java,Input,我想做的是让“for”有一个用于该计算的joption输入,而不是系统输入 String me = JOptionPane.showInputDialog("Please input a username!"); JOptionPane.showMessageDialog(null,"Your name is: " + me); String user = JOptionPane.showInputDialog("Please enter your choice!"); JOpt
String me = JOptionPane.showInputDialog("Please input a username!");
JOptionPane.showMessageDialog(null,"Your name is: " + me);
String user = JOptionPane.showInputDialog("Please enter your choice!");
JOptionPane.showMessageDialog(null, "Your choice is: " + user);
String numbers = JOptionPane.showInputDialog("Please enter a set of numbers!");
int n, c, fact = 1;
if(user.equals("1"))
JOptionPane.showMessageDialog(null, "" + me + "" + numbers);
else if(user.equals("2"))
JOptionPane.showInputDialog("Please enter a number to calculate a Factoral Username");
Scanner in = new Scanner(System.in);
n = in.nextInt();
if ( n < 0 )
JOptionPane.showMessageDialog(null, ("Number should be non-negative."));
else
{
for ( c = 1 ; c <= n ; c++ )
fact = fact*c;
JOptionPane.showMessageDialog(null, ("New username is: " + me + fact));
String me=JOptionPane.showInputDialog(“请输入用户名!”);
showMessageDialog(null,“您的名字是:“+me”);
字符串user=JOptionPane.showInputDialog(“请输入您的选择!”);
showMessageDialog(null,“您的选择是:“+user”);
String numbers=JOptionPane.showInputDialog(“请输入一组数字!”);
int n,c,fact=1;
if(用户等于(“1”))
showMessageDialog(null,“+me+”+number);
else if(用户等于(“2”))
showInputDialog(“请输入一个数字来计算系数用户名”);
扫描仪输入=新扫描仪(系统输入);
n=in.nextInt();
if(n<0)
showMessageDialog(null,(“数字应该是非负的”);
其他的
{
对于(c=1;c将对话框调用的结果分配给变量,然后将其转换为整数:
String input = JOptionPane.showInputDialog("Please enter a number");
try {
int n = Integer.parseInt(input);
// ....
} catch (NumberFormatException e) {
// Exception when input is not in integer format
// or is null when user press cancel button
}
我将把这个放在哪里?用这个代码替换扫描器
初始化和nextInt
调用。然后把如果给定值被成功解析的代码放在try
块中。