Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Write a description of class guessingGame here.
- *
- * @Arjun Bhamra
- * @9/6/19
- */
- import java.util.*;
- public class TempConverter
- {
- public static void main(String args[]){
- tempConvert();
- Scanner kb = new Scanner(System.in);
- System.out.println("Press 1 to convert another temp, Press 2 if not");
- int choice = 1;
- while(choice==1){
- choice=kb.nextInt();
- if(choice==1){
- tempConvert();
- choice=0;
- } else if(choice==2){
- System.out.println("Thank you for using this converter!");
- }
- }
- }
- public static void tempConvert(){
- //Entering a temperature to convert
- Scanner scan = new Scanner(System.in);
- System.out.println("Please enter a temperature: ");
- int temp = scan.nextInt();
- //Whether to convert from Celcius to Fahrenheit or vice versa.
- Scanner sc = new Scanner(System.in);
- System.out.println("C->F is 1, F->C is 2");
- int conversion = sc.nextInt();
- if(conversion==1 || conversion==2){
- if(conversion==1){
- double x=((9.0/5*temp)+32);
- System.out.println(temp + " degrees Celcius is " + (int)x + " degrees Fahrenheit");
- } else if(conversion==2){
- double y=(temp-32)*5/9.0;
- System.out.println(temp + " degrees Fahrenheit is " + (int)y + " degrees Celcius");
- }
- } else {
- System.out.println("You inputted something incorrect! Try again.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement