Java Online Compiler
Example: Convert Celsius into Fahrenheit in Java Program using Function
C
C++
C#
Java
Python
PHP
Main.java
STDIN
Run
// Convert Celsius into Fahrenheit in Java Program using Function import java.util.Scanner; public class Main { // This function will convert the celsius into fahrenheit public static float CelcToFahren(float x) { return (float)((x * 9 / 5) + 32); } // It's the driver function public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("Enter the temperature in Celsius::\n"); float c = in.nextFloat(); // c = celsius // It will print the final output System.out.println(c + " Celsius = " + CelcToFahren(c) + " Fahrenheit"); } }
10
Output
Clear
ADVERTISEMENTS