Java Program Source Code for Converting a value from Celsius to Fahrenheit or Vice Versa
Hello world ! This time we'd like to share you java source code for program to convert a value from Celsius to Fahrenheit or vice versa.
Here's how the result look like :
import java.util.Scanner; public class Konversi { public static void main(String[] arguments) { Scanner in2; double res = 0; System.out.println("Please select,\n1. C to F\n2. F to C"); Scanner in1 = new Scanner(System.in); System.out.print("= "); switch(in1.nextInt()){ case 1: System.out.println("C = "); in2 = new Scanner(System.in); res = in2.nextInt() * 9 / 5 + 32; break; case 2: System.out.println("F = "); in2 = new Scanner(System.in); res = (in2.nextInt() - 32) * 5 / 9; break; default: System.err.println ("Unrecognized option"); break; } System.out.println("\n Result is " + res); }}
Here's how the result look like :
The program will ask you what conversion you world like to choose. If you select '1' then you must input Celsius value to get Fahrenheit value. If you sselect '2' then you must input Fahrenheit value to get Celsius value.
Comments
Post a Comment