【发布时间】:2016-08-01 18:30:14
【问题描述】:
我是编程新手,并且很难创建一个程序,该程序将从 for 循环中的数组收集的数据显示到表中。我能够收集数据,但无法存储并在之后显示。有什么想法吗?
这是我写的
import java.util.Scanner;
//Fahrenheit to Celsius converter
public class CelsiusConversion
{
public static void Celsius(String[] args)
{//Open method 1
int num;
double [] temps;
double fahrenheit;
Scanner input = new Scanner(System.in);
System.out.println("Enter the amount of numbers you wish to average: ");
num = input.nextInt();
while (num<1)
{
System.out.println("You did not enter a number greater than zero. Please enter a number greater than zero:");
num = input.nextInt();
}
temps = new double [num];
for (int t = 0; t <num; t++)
{
System.out.println("Enter temperature " + (t+1) + " in Fahrenheit:");
temps[t] = input.nextDouble();
System.out.println("Please confirm the temperature in Fahrenheit");
fahrenheit = input.nextDouble();
double celsius = 5.0/9*(fahrenheit - 32);
System.out.println( fahrenheit + " in Celsius is " + celsius + ".");
}
}//Close method 1
}
【问题讨论】:
-
如果可能的话,我希望数据显示在 for 循环之外
-
贴出你已经尝试过的代码。请把它作为编辑而不是 cmets 放在问题上。
-
请提供代码示例并详细说明什么不起作用,您想要什么以及您遇到的错误
-
什么样的桌子?
JTable?html表?