Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/378.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我的计算需要和作业输入,而不是system.output_Java_Input - Fatal编程技术网

Java 我的计算需要和作业输入,而不是system.output

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

我想做的是让“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!");
  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
块中。