Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class TempConverter {
- public static void main(String[] args) {
- boolean inUse = true;
- Scanner in = new Scanner(System.in);
- while(inUse) {
- System.out.println("----------- Temperature Converter -----------");
- System.out.println("\tCelsius to Fahrenheit: Type 1");
- System.out.println("\tFahrenheit to Celsius: Type 2");
- int conversionType = in.nextInt();
- if(conversionType == 1) {
- System.out.println("Celsius to Fahrenheit mode.");
- }
- else if(conversionType == 2) {
- System.out.println("Fahrenheit to Celsius mode.");
- }
- System.out.print("What temperature do you want to convert? ");
- double temp = in.nextDouble();
- double output;
- if(conversionType == 1) {
- output = (9.0/5 * temp) + 32;
- System.out.println(temp + "°C = " + output + "°F");
- }
- else if(conversionType == 2) {
- output = (temp - 32) * 5/9.0;
- System.out.println(temp + "°F = " + output + "°C");
- }
- System.out.println("Do you want to convert a different temperature? (y/n)");
- String userCont = in.next();
- if(userCont.equals("yes") || userCont.equals("y")) {
- inUse = true;
- }
- else if(userCont.equals("no") || userCont.equals("n")) {
- inUse = false;
- }
- }
- in.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement