У меня возникли проблемы с заданием в моей книге. Я пишу супер простое приложение, которое преобразует Фаренгейт в celcius и наоборот. Все работает отлично, за исключением того, что модуль, который я написал для преобразования Фаренгейта в celcius, возвращает нуль. Я не могу понять это, я был отлажен в Eclipse, перешагнув каждый шаг, и я не могу понять, что не так с моим уравнением преобразования f> c, или что еще может быть. Может ли кто-нибудь более опытный, чем я, видеть проблему? Я бы очень признателен за осмотр. Спасибо!отладка логической ошибки в модуле
import java.util.Scanner;
public class TemperatureConversions
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
String initialType;
double fahrenheit = 1;
double celcius = 1;
System.out.print("Would you like to enter a fahrenheit or celcius temperature for conversion? (f/c): ");
initialType = input.next();
switch (initialType)
{
case "f":
System.out.printf("Please input fahrenheit temperature: ");
fahrenheit = input.nextDouble();
celcius = celcius (fahrenheit);
System.out.print("\n" + fahrenheit + "f converted to celcius is " +celcius + "c");
break;
case "c":
System.out.printf("Please input celcius temperature: ");
celcius = input.nextInt();
fahrenheit = fahrenheit (celcius);
System.out.print("\n" + celcius + "c converted to fahrenheit is " + fahrenheit + "f");
break;
default:
System.out.printf("%s is an invalid input. Please try again, and only input either 'f' or 'c'");
break;
}
System.out.printf("\nAdios Turd Nuggets");
}
public static double celcius(double f)
{
double c = 5/9 * (f - 32);
return c;
}
public static double fahrenheit(double c)
{
double f = c * 1.8 + 32;
return f;
}
}
Спасибо! Я попробую. –
Ahhh это работает !!!! Ты жжешь!!!!! –
Если это сработает, примите этот ответ - http://stackoverflow.com/help/someone-answers –