473,407 Members | 2,306 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,407 developers and data experts.

How to convert Fahrenheit to Celsius

10
The Java code for this temperature conversion from Fahrenheit to Celsius is given below. the code starts by asking the user to enter a temperature in Fahrenheit scale and then displays the equivalent Celsius Temperature.



Expand|Select|Wrap|Line Numbers
  1. /////////////////////////////////
  2.  
  3. package developer;
  4.  
  5.  
  6.  
  7. import java.util.Scanner;
  8.  
  9.  
  10.  
  11. public class FahrenheitToCelsius {
  12.  
  13.  
  14.  
  15.     public static void main(String[] args) {
  16.  
  17.         System.out.println("Enter a temperature in Fahrenheit: ");
  18.  
  19.         Scanner scanFaren = new Scanner(System.in);
  20.  
  21.         double Celsius = 0;
  22.  
  23.  
  24.  
  25.         if(scanFaren.hasNextDouble())
  26.  
  27.         {
  28.  
  29.             Celsius = (scanFaren.nextDouble() - 32)*5/9;
  30.  
  31.         }
  32.  
  33.         System.out.println("The temperature in Celsius is: "+Celsius);
  34.  
  35.  
  36.  
  37.     }
  38.  
  39. }
  40.  
  41. /////////////////////////////////
  42.  
  43.  
  44.  
  45. When this Java Code was executed on my JVM, then the output was as shown below.
  46.  
  47.  
  48.  
  49. /////////////////////////////////
  50.  
  51. Enter a temperature in Fahrenheit: 
  52.  
  53. 56
  54.  
  55. The temperature in Celsius is: 13.333333333333334
  56.  
  57. /////////////////////////////////
  58.  

Hope that the Java code provide for conversion from Fahrenheit to Celsius was useful to you all.
Feb 17 '10 #1
0 6697

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: sjsn | last post by:
Basic C++, just started this course in school... So I'm very limited. What I'm at doing is, below I have a variable named inputTemp, which is the product of a char, F = Fahrenheit, C = Celsius...
2
by: lifeshortlivitup | last post by:
I am a java beginner and am trying to tackle a temperature conversion problem but I don't exactly know how to begin. The problem asks that I write a program that allows the user to conver either...
4
by: kipj77 | last post by:
Hi i was wondering why the hell this program isn't working for me, I am in a 100 level computer science class and need help. This program is supposed to take in data of degrees Fahrenheit and spit...
1
by: sigkill9 | last post by:
I'm new to Python and am trying to figure out how to streamline the code at bottom to get it more simple but am having trouble. I was hoping that someone here could help me out? The program I am...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.