Thursday, January 28, 2016

JAVA CELSIUS TO FAHRENHEIT: Celsius to Fahrenheit Java Converter Code

Hi there! This article will create a simple temperature converter from Fahrenheit to Celsius and vice versa. We will be using the following formula to solve for value in Fahrenheit to Celsius and Celsius to Fahrenheit using java language.

Visit my post about Celsius to Fahrenheit in PHP here.

Formula
C  x  9/5 + 32 = F
(F  -  32)  x  5/9 = C

First, we will convert Celsius to Fahrenheit. Let's try to convert 32 degrees Celsius to degrees Fahrenheit.

Java Code
Celsius to Fahrenheit

import java.util.Scanner; 
public class TempConverter{

public static void main(String[] args) {

// convert celsius to fahrenheit
double celsius = 32;
double f=celsius*9/5+32;
System.out.printf("%.2f Celsius is equivalent to %.2f in Fahrenheit\n",celsius,f);
        double fahrenheit = 89.6; 
double c=(fahrenheit-32)*5/9;
System.out.printf("%.2f Fahrenheit is equivalent to %.2f in Celsius",fahrenheit,c);
}
}

Output



JAVA CELSIUS TO FAHRENHEIT: Celsius to Fahrenheit Java Converter Code

JAVA CELSIUS TO FAHRENHEIT: Celsius to Fahrenheit Java Converter Code Rating: 4.5 Diposkan Oleh: Emoblazz

0 comments:

Post a Comment