Hi there! The following tutorial will introduce you to one of the most common problems encountered in programming subjects. Later on, I will provide set of activities and quizzes for you to practice on to improve your programming skills.
A temperature converter made in java is just one of the exercises given by most programming instructors. Some other exercises are the following:
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 Celsius to Fahrenheit
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 CodeCelsius 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);
}
}
No comments:
Post a Comment