我的部分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++;
}
}
}
答案 0 :(得分:1)
根据你的代码你有一个while循环
while(wsp <= c) {...}
然后你有一个for循环
for (ws = wsp; ws <= c; ws += 0.5)
因此,您可以看到为ws
分配了wsp
的值,该值已经超过了c