My code for converting temperatures...
Hello All,
I just stayed around 6 hours to try and figure out how to write a code to convert Fahrenheit to Celsius. Here's my code:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class fahrenheitcelsius {
public static void main (String[]args)
throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the Temperature in Fehrnheit");
String degree;
degree = br.readLine();
int c = Integer.parseInt(degree);
c = (int) ((c-32)*(5)/(9));
System.out.println("The Temprature in Fahrenheit is \n"+c);
}
}
I wanna know if this is considered good for someone that doesn't have any programming background. Also I wanted to know If I can use an IF statement to make the program not only convert from Fahrenheit to Celsius but vice-versa. Anyways here's what I had in mind:
if(br.readLine() == C){
System.out.println("Enter the Temperature in Celsius");
String degree1;
degree1 = br.readLine();
int f = Integer.parseInt(degree1);
f = (int) (( f -32)*(0.55))
System.out.println("The Temperature in Celsius is \n" +f);
}else{
System.out.println("Enter the Temperature in Fahrenheit")
String degree;
degree = br.readLine();
int c = Integer.parseInt(degree);
c = (int) ((c*(9/5))+32)
System.out.println("The Temperature in Celsius is\n"+c);
But I couldn't get that to work , and because it's my first time on java ever I don't know if i'm really on the track or not.