Skip to content

Instantly share code, notes, and snippets.

@NickCarneiro
Forked from anonymous/gist:1787021
Created February 10, 2012 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NickCarneiro/1792162 to your computer and use it in GitHub Desktop.
Save NickCarneiro/1792162 to your computer and use it in GitHub Desktop.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Temperature{
public static void main(String[] args){
//the data that will be entered by the user
String farenheit1;
//an instance of the BufferedReader class
//will be used to read the data
BufferedReader reader;
//specify the reader variable
//to be a standard input buffer
reader = new BufferedReader(new InputStreamReader(System.in));
System.out.println("What is the farenheit?");
try{
//read the data entered by the user using
//the readLine() method of the BufferedReader class
//and store the value in the name variable
float farenheit = Float.parseFloat(reader.readLine());
float celsius = (farenheit-32)*5/9;
//print the data entered by the user
System.out.println("The fahrenheit is " + farenheit);
System.out.println("The celcius is " + celsius);
}
catch (IOException ioe){
//statement to execute if an input/output exception occurs
System.out.println("An unexpected error occured.");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment