Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class TemperatureConvert {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String convert = "yes";
- while(convert.equals("yes")) {
- int ans;
- System.out.println("Would you like to: \n 1) Convert Celcius to Fahrenheit \n 2) Convert Fahrenheit to Celcius");
- ans = sc.nextInt();
- if(ans!=1 && ans!=2) {
- System.out.println("Invalid option.");
- }
- else if(ans == 1) {
- System.out.println("What (interger) temperature would you like to convert? (°C)");
- int Ctemp = sc.nextInt();
- double CtoF = ((9.0/5)*Ctemp)+32;
- System.out.println(Ctemp+"°C is "+CtoF+"°F");
- }
- else if(ans==2) {
- System.out.println("What (interger) temperature would you like to convert? (°F)");
- int Ftemp = sc.nextInt();
- double FtoC = (Ftemp-32)*(5.0/9);
- System.out.println(Ftemp+"°F is "+FtoC+"°C");
- }
- System.out.println("Convert again? (yes/no)");
- convert = sc.next();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement