Codex

Temperature Converter

Jul 1st, 2011
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 KB | None | 0 0
  1. import java.io.*;
  2. class Temperature
  3. {
  4.  BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  5.  int ch;
  6.  double cel,Fah;
  7.  void convert() throws IOException
  8.  {
  9.      System.out.println("1.Celsius to Fahrenheit");
  10.      System.out.println("2.Fahrenheit to Celsius");
  11.      System.out.println("Enter choice(1/2)");
  12.      ch=Integer.parseInt(br.readLine());
  13.      switch(ch)
  14.      {
  15.      
  16.      case 1: System.out.println("Enter temperature in Celsius");
  17.              cel=Double.parseDouble(br.readLine());
  18.              Fah=(9*cel)/5+32;
  19.              System.out.println("Converted temperature in Fahrenheit = "+Fah);
  20.              break;
  21.      case 2: System.out.println("Enter temperature in Fahrenheit");
  22.              Fah=Double.parseDouble(br.readLine());
  23.              cel=(Fah-32)*5/9;
  24.              System.out.println("Converted temperature in Celsius = "+cel);
  25.              break;
  26.     default: System.out.println("Invalid choice");
  27.              break;
  28.     }
  29.        
  30.          
  31.    
  32.  }
  33.  public static void main(String args[])
  34.  {
  35.   Temperature t=new Temperature();
  36.   t.convert();
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment