Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Converter {
- public static void main(String[] args) {
- Scanner keyboard = new Scanner(System.in);
- System.out.println("Welcome to the Fahrenheit/Celsius Converter!");
- System.out
- .println("To convert, type in your temperature and the identify if you are using fahrenheit or celsius.");
- System.out.println("Example: 69F or 69C F = Fahrenheit C = Celsius");
- String temperature;
- char f = 'f';
- char c = 'c';
- char C = 'C';
- double answer, temp;
- temperature = keyboard.nextLine();
- if (temperature.contains("C")) {
- temperature = temperature.replace(C, ' ');
- temp = Double.valueOf(temperature);
- answer = (double) (temp * (9 / 5) + 32);
- System.out.println("Poof! The temperature is " + answer + "F");
- } else if (temperature.contains("c")) {
- temperature = temperature.replace(c, ' ');
- temp = Double.valueOf(temperature);
- answer = (double) (temp * (9 / 5) + 32);
- System.out.println("Poof! The temperature is " + answer + "F");
- } else if (temperature.contains("F")) {
- temperature = temperature.replace(f, ' ');
- temp = Double.valueOf(temperature);
- answer = (double) ((temp - 30) * (5 / 9));
- System.out.println("Poof! The temperature is " + answer
- + "C");
- } else if (temperature.contains("f")) {
- temperature = temperature.replace(f, ' ');
- temp = Double.valueOf(temperature);
- answer = (double) ((temp - 30) * (5/9));
- System.out.println("Poof! The temperature is " + answer
- + "C");
- } else {
- System.out.println("You entered the temperature wrong!");
- }
- keyboard.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement