Loading
View RSS Feed

Harsh Chowdhary's Blog

Temperature Conversion In Java (Celsius To Fahrenheit and Fahrenhiet To Celsius)

Rate this Entry
This is a simple java program that will convert celcius to farheneit. It simply converts Celsius to Fahrenheit and Fahrenheit to Celsius. Input a temperature and it'll give you both conversions.

Code:
import java.util.Scanner;
 
class TempConverter {

	public static void main(String[] args) {
		int temp,far,cel;
		System.out.print("What is the temperature you'd like to convert?  ");
		Scanner myScanner = new Scanner(System.in);
		temp = myScanner.nextInt();
		far = temp * 9 / 5 + 32; //use this line if Celsius to Fahrenheit
		cel = (temp - 32) * 5 / 9; // use this line if Fahrenheit to Celsius
 		System.out.println("Fahrenheit --> Celsius: " + cel); //use this line if Celsius to Fahrenheit
		System.out.println("Celsius --> Fahrenheit: " + far);// use this line if Fahrenheit to Celsius
	}	
}
The above code basically demonstrates input and output in Java using Scanner Class.

Submit "Temperature Conversion In Java (Celsius To Fahrenheit and Fahrenhiet To Celsius)" to Digg Submit "Temperature Conversion In Java (Celsius To Fahrenheit and Fahrenhiet To Celsius)" to del.icio.us Submit "Temperature Conversion In Java (Celsius To Fahrenheit and Fahrenhiet To Celsius)" to StumbleUpon Submit "Temperature Conversion In Java (Celsius To Fahrenheit and Fahrenhiet To Celsius)" to Google

Updated 02-05-2011 at 07:50 AM by Harsh

Tags: java
Categories
Java

Comments




Disclaimer: Users of techforum4u.com are responsible for ensuring that any material they post (article, blog posts, images or other mulitimedia content) does not violate or infringe upon the copyright, patent, trademark, or any personal or proprietary rights of any third party, and is posted with the permission of the owner of such rights.Anyone who violates these rules may have their access privileges removed without warning.