Description
This basic java example source code reads the temperature in degrees Celsius from console and calculate the equivalent in Kelvin.
Degree Celsius to Kelvin Conversion Source Code
package com.javatutorialhq.java.examples; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; /* * This basic java example source code * reads temperature in degrees Celsius from console input * Java Program to convert Degree Celsius to Kelvin */ public class ConvertCelsiusKelvin { public static void main(String[] args) throws NumberFormatException, IOException { // Declare the reader from console BufferedReader br; // Get the console input for the temperature in degree Celsius System.out.println("Temperature in Degree Celsius:"); br = new BufferedReader(new InputStreamReader(System.in)); // assign to float variable the degree celsius float celsius = Float.parseFloat(br.readLine()); // Degrees Celsius to Kelvin Conversion float kelvin = celsius + 273.15F; System.out.println("Kelvin: "+ kelvin); } }
Sample Output
Temperature in Degree Celsius: 123 Kelvin: 396.15