Conversion Learn programming Java

Lesson:

First contact with Java


Exercise:

Conversion


Objetive:

Create a java program to convert Celsius degrees to Kelvin and Fahrenheit. The program will prompt the user to input the temperature in Celsius degrees, and then use the following conversion formulas:

Kelvin = Celsius + 273
Fahrenheit = Celsius x 1.8 + 32

The program will then display the equivalent temperature in both Kelvin and Fahrenheit units.


Code:

import java.util.*;
public class Main
{
	static void main(String[] args)
	{
		System.out.print("Enter the amount of celsius: ");
		int celsius = Integer.parseInt(new Scanner(System.in).nextLine());
		System.out.printf("Kelvin = %1$s" + "\r\n", celsius + 273);
		System.out.printf("Fahrenheit = %1$s" + "\r\n", celsius * 18 / 10 + 32);
	}
}

Juan A. Ripoll - Systems Tutorials and Programming Courses ©  All rights reserved.  Legal Conditions.