I am fairly new at this and any help would be appreciated . thx
private static int doFarenheitCelsius()
{
util.writeln("\nYou chose Farenheit or Celsius");
Scanner reader = new Scanner(System.in);
double temp = 0;
double convertedF = 0;
double convertedC = 0;
DecimalFormat df = new DecimalFormat("#.##");
util.writeln("Enter a temperature ");
temp = reader.nextInt();
String strInput = "0";
util.writeln("Convert to Farenheit or Celsius");
strInput = reader.nextLine();
char letter = strInput.charAt(0);
if (letter == 'F' && letter == 'f')
{
convertedF = temp * 9/5 + 32;
util.writeln(temp + "is " + df.format(convertedF) + " Degrees Ferenheit");
}
else if (letter == 'C' && letter == 'c')
{
convertedC = (temp - 32) * 5 / 9;
util.writeln(temp + "is " + df.format(convertedC) + " Degrees Celsius");
}
return 0;
}
and my error message is as below, seems like a simple method to execute
You chose Farenheit or Celsius
Enter a temperature
45
Convert to Farenheit or Celsius
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 0
at java.lang.String.charAt(Unknown Source)
at exercises.SuperCalculatorAssignmentFive.doFarenhei tCelsius(SuperCalculatorAssignmentFive.java:132)
at exercises.SuperCalculatorAssignmentFive.main(Super CalculatorAssignmentFive.java:73)