Temperature Conversion System
Temperature Conversion System
Temperature of city in Fahrenheit degrees is input through the keyboard. write a program to convert this temperature into centigrade.
package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// write your code here
float fahrenheit, centigrade, temp;
int choice;
System.out.println("Temperature conversion system ");
System.out.println("1. Fahrenheit to Centigrade");
System.out.println("2. Centigrade to Fahrenheit");
System.out.print("your choice : ");
Scanner sc = new Scanner(System.in);
choice = sc.nextInt();
if (choice==1)
{
System.out.print("Fahrenheit : ");
fahrenheit= sc.nextFloat();
centigrade= (float) (-17.2222222*fahrenheit);
System.out.println("After conversion in Centigrade : "+centigrade+" C");
}
else if (choice==2)
{
System.out.print("Centigrade : ");
centigrade= sc.nextFloat();
fahrenheit= (float) (33.8*centigrade);
System.out.println("After conversion in Centigrade : "+fahrenheit+" F");
}
else {
System.out.println("Enter correct choice");
}
}
}
output:-
Temperature conversion system
1. Fahrenheit to Centigrade
2. Centigrade to Fahrenheit
your choice : 1
Fahrenheit : 23
After conversion in Centigrade : -396.1111 C
Process finished with exit code 0
Temperature conversion system
1. Fahrenheit to Centigrade
2. Centigrade to Fahrenheit
your choice : 2
Centigrade : 23
After conversion in Centigrade : 777.4 F
Process finished with exit code 0
Temperature conversion system
1. Fahrenheit to Centigrade
2. Centigrade to Fahrenheit
your choice : 5
Enter correct choice
Process finished with exit code 0
Comments
Post a Comment