Advertisement
Myrmex

Converter

Jul 16th, 2011
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.64 KB | None | 0 0
  1. public class Main {
  2.  
  3.     public static void main(String[] args) {
  4.  
  5.         Conv cf = new Conv();
  6.         cf.convTemp('F');
  7.     }
  8. }
  9.  
  10.  
  11. public class Conv {
  12.  
  13.     float temp = 36;
  14.     char convTo;
  15.  
  16.     public void convTemp(char convTo) {
  17.  
  18.         if (convTo == 'F') {
  19.             System.out.println("Current temperature is " + temp + "C");
  20.             temp = (temp - 32) * (5 / 9);
  21.             System.out.println("That equals to " + temp + "F");
  22.         } else if (convTo == 'C') {
  23.             System.out.println("Current temperature is " + temp + "F");
  24.             temp = (temp + 32) * (9 / 5);
  25.             System.out.println("Temperature equals to " + temp + "C");
  26.         } else {
  27.             System.out.println("Undefined value");
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement