我需要帮助完成这项任务.**这是我需要程序做的:
- 编写一个程序,提示用户进行多次迭代.
- 程序应该循环多次.
- 每个循环程序应提示用户输入一个数字并将其添加到运行总计中.
- 完成后打印运行总计.
我不能让程序循环多次用户输入.我知道这是一个简单的修复,但我似乎无法弄明白.我在循环中使用了错误的语句吗?
Scanner guess = new Scanner(System.in);
int count =0;
int sum=0;
int num;
System.out.println("Enter a number");
num = guess.nextInt();
for(count =0; count <= num; count++)
{
sum +=num;
System.out.println("Your results are:"+sum);
}
Run Code Online (Sandbox Code Playgroud) 我一直得到一个错误变量F3可能尚未在您看到的最后一行代码中初始化.
我究竟做错了什么?
{
Float F1,F2, F3;
F1 = Float.parseFloat(
JOptionPane.showInputDialog("Enter a number and press ok."));
F2 = Float.parseFloat(
JOptionPane.showInputDialog("Enter a second number and press ok."));
if(F1 >= F2)
{
F3=(F1 * F2) + (F1 * 2);
}
if(F2 >= F1)
{
F3 =(F1 + F2) + (F2 * 5);
}
DecimalFormat dec = new DecimalFormat("##.##");
JOptionPane.showMessageDialog(null,"Your calculations are:" +(F3),"Caculations", JOptionPane.INFORMATION_MESSAGE);
Run Code Online (Sandbox Code Playgroud)