0
我的部分java代码未运行。我对Java相当陌生,一直在研究一些新的环境变化。我的班级被告知要建立一个Windchill温度计算器。我的主要问题是,我的代码工作到for(ws = wsp; ws < = c; ws + = 0.5)然后停止。部分代码未运行
import java.util.*;
class Assign1
{
public static void main(String args[])
{
Menu user = new Menu();
Menu.mainmenu();
user.acceptSelection();
}
}
class Menu
{
public static void mainmenu()
{
System.out.println("Temperature Analysis MENU");
System.out.println("1.W)ind Chill Temperature");
System.out.println("0.E)xit");
System.out.println("Enter Selection:");
}
public void acceptSelection()
{
Scanner stdin = new Scanner(System.in);
String selection = stdin.nextLine();
char choice = selection.charAt(0);
switch(choice)
{
case 'W':
case 'w':
case '1':
processing.process(); break;
case 'E':
case 'e':
case '0':
System.out.println("E"); break;
}
}
}
class processing
{
public static void process()
{
Scanner stdin = new Scanner(System.in);
System.out.println("\n\n\n\n\n\n\n");
System.out.print("Please enter START air temp in celsius (decimal) MUST be BELOW 9: ");
double sa = stdin.nextDouble();
System.out.print("Please enter END air temp in celsius (decimal) MUST be BELOW 9: ");
double ea = stdin.nextDouble();
System.out.print("Please enter wind speed (decimal) FROM 8km/h to: ");
double w = stdin.nextDouble();
System.out.println("\n==================================================================\n");
calculation(sa, ea, w);
}
public static void calculation(double a, double b, double c)
{
double wsp = 8.0;
double airTemp;
double ws;
int size = 150;
double[] wChill = new double[size];
int count = 0;
System.out.print(" " + a);
while(a <= b)
{
System.out.print(" " + a);
a +=5;
count++;
}
System.out.print(" " + b);
int count2 = 0;
while(wsp <= c)
{
count2++;
wsp += 0.5;
}
double[][] chart = new double[count2][count];
int i = 0, j = 0, k = 0;
这是停止工作的地方。我无法将它打印出来。任何帮助解决我的问题将不胜感激,以及笔记我的代码,因为我想改善。如果有帮助,我正在使用JGrasp。
for (ws = wsp; ws <= c; ws += 0.5)
{
System.out.println(ws + " ");
for (airTemp = a; airTemp <= b; airTemp += 5.0)
{
if ((ws + 0.5) > c)
{
System.out.printf("%2d %2d", c , chart[k][i]);
}
else
{
wChill[i] = (13.12 + (0.6215*airTemp)+(-11.37*Math.pow(ws, 0.16))+(0.3965*airTemp*Math.pow(ws, 0.16)));
chart[k][i] = wChill[i];
System.out.print(chart[k][i] + " ");
}
i++;
}
k++;
}
}
}
它如何停止工作?崩溃?错误的值出来了?它进入一个无限循环?请添加更多关于出错的信息,以及您对'a','b'和'c'的值(我强烈建议将其重命名为'startTemp','endTemp'和'maxWindSpeed'等更有意义的名称。并且Eclipse有一个内置的调试器;学会使用它,因为在for(ws = wsp; ...)上放置一个断点将提供很多信息。 –
欢迎来到Stack Overflow!为了给你一个很好的答案,它可能会帮助我们,如果你有一个[问],如果你还没有看过它,它可能也是有用的,如果你可以提供[mcve] – Mat