4 Hours of struggles, no result..Completely stuck with my dull brain and need help..
import java.util.Scanner; public class Project5 { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); double temp; System.out.print("Enter a temperature in degrees: "); temp = keyboard.nextDouble(); System.out.print("Enter either letter C or F to indicate degrees Celsius or Fahrenheit, respectively: "); String s1 = keyboard.nextLine(); String s2 = keyboard.nextLine(); double Degrees_C = temp; double Degrees_F = temp; String c = s1; String C= s1; String F=s2; String f=s2; if (s1.equals(s1)) { Degrees_F = (9 * ((Degrees_C) / 5) + 32); System.out.print(temp + " degrees Fahrenheit is " + Degrees_F + " degrees Celsius.");} else if (s2.equals(s2)){ Degrees_C = (5 * (Degrees_F - 32) / 9); System.out.print(temp + " degrees Celsius is " + Degrees_C + " degrees Fahrenheit.");} else { System.out.print("You either entered the wrong value or did not enter a letter C nor F.");} } }
It actually shows C to F really well.
The problems that I'm facing is that:
1. It doesn't convert F to C (Shows the C to F instead).
2. It doesn't display the error message when entering any letters other than C, c, f, or F. (EDIT) I don't think my code can read alphabet..
3. There can be too much decimal place...Any way to limit how far the decimal could go?
Thank you very much.