Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *This code converts a temperature to Celsius or Fahrenheit
- *
- * @Molly Limaye
- * @09/05/19
- */
- import java.util.*;
- public class TempConverter {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- //play again loop
- int run = 1;
- while (run==1){
- //user input
- System.out.print("Enter a temperature: ");
- double temp = sc.nextInt();
- System.out.println("Enter 1 to convert to Celsius.\nEnter 2 to convert to Fahrenheit.");
- int convert = sc.nextInt();
- String unit = "F";
- //conversions
- if (convert==1){
- temp = (temp - 32) * 5/9.0;
- unit = "C";
- }
- else {
- temp = ((9.0/5 * temp) + 32);
- }
- System.out.println("The temperature is " + temp + "ΒΊ" + unit + ".");
- //play again feature
- System.out.println("Would you like to convert another temperature? (1=yes/2=no)");
- int answer = sc.nextInt();
- if (answer==1){
- run = 1;
- }
- else{
- run = 0;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement