Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth
Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

42,690 questions

55,449 answers

573 users

How to convert fahrenheit to celsius in Java

3 Answers

0 votes
import java.util.Scanner;
 
public class MyClass 
{
    public static void main(String[] args) 
    {
        try
        {
            Scanner in = new Scanner(System.in); 
            System.out.print("Enter Temperature in Fahrenheit: ");
            int temp_f = in.nextInt();
            double temp_c = FahrenheitToCelsius(temp_f);
            System.out.format("%d Fahrenheit = %.2f Celsius\n", temp_f, temp_c); 
        }
        catch (Exception e)
        {
           System.out.println(e.toString());
        }  
    }
    static double FahrenheitToCelsius(int f)
    {
        double t;
  
        t = (f - 32.0) / 1.8;
  
        return t;
    }
}


 
/*
 
run 1:
 
Enter Temperature in Fahrenheit: 1
1 Fahrenheit = -17.22 Celsius
 
run 2:
  
Enter Temperature in Fahrenheit: 50
50 Fahrenheit = 10.00 Celsius
 
*/


answered May 6, 2015 by avibootz
edited Jul 20, 2022 by avibootz
0 votes
import java.util.Scanner;
 
public class MyClass 
{
    public static void main(String[] args) 
    {
        try
        {
            Scanner in = new Scanner(System.in); 
            System.out.print("Enter Temperature in Fahrenheit: ");
            int temp_f = in.nextInt();
            double temp_c = FahrenheitToCelsius(temp_f);
            System.out.format("%d Fahrenheit = %.2f Celsius\n", temp_f, temp_c); 
        }
        catch (Exception e)
        {
           System.out.println(e.toString());
        }  
    }
    static double FahrenheitToCelsius(int f)
    {
        double t;
  
        t = (f - 32) * (5.0 / 9.0);
  
        return t;
    }
}



 
/*
 
run 1:
 
Enter Temperature in Fahrenheit: 1
1 Fahrenheit = -17.22 Celsius
 
run 2:
  
Enter Temperature in Fahrenheit: 50
50 Fahrenheit = 10.00 Celsius
 
*/
 


answered May 6, 2015 by avibootz
edited Jul 20, 2022 by avibootz
0 votes
public class MyClass {
    public static void main(String args[]) {
        int fahrenheit = 96;
       
        double celsius = (fahrenheit - 32) * 5 / 9.0;
 
        System.out.println("Celsius = " + celsius);
    }
}
 
   
   
   
/*
run:
     
Celsius = 35.55555555555556
    
*/

 



answered Jul 22, 2022 by avibootz

Related questions

1 answer 132 views
1 answer 206 views
1 answer 146 views
1 answer 151 views
1 answer 144 views
1 answer 144 views
1 answer 138 views
...