0

I was creating a program that converts Farenheit to Celcius and vice versa. For some reason, the output is stuck on the first question. For my input, I typed in a double (6.99). I then clicked enter. When and after I type enter, the cursor moves downwards and it will keep on moving downwards until I type in a character or a string to then hit enter. How do I fix this? Here's my code:

import java.util.*;

//syntax for taking a number to the power is pow(base, exponent)
public class Main
{
    public static void main(String[] args) {
        
        Scanner input = new Scanner(System.in);
        
        
        System.out.println("What is your temperature? ");
        double temp1 = input.nextDouble();
        
        input.nextDouble();
        
        System.out.println("What degrees is that in?");
        String degrees1 = input.nextLine();

        
        if(degrees1.equals("Farenheit") || degrees1.equals("F") || degrees1.equals("farenheit"))
        {
            System.out.println("What do you want to convert to?");
            String degrees2 = input.nextLine();
            
            if(degrees2.equals("Celsius") || degrees2.equals("C") || degrees2.equals("celsius"))
            {
                double farenheitToCelsius = (5*(temp1 - 32))/9;
                System.out.println(temp1 + " in ");
            }
            
        
        }
        else
        {
            System.out.println("Invalid temperature");
        }
                
    }
}
zackBYE344
  • 63
  • 5
  • What do you mean by "is stuck"? What do you mean by "did not work"? – Karl Knechtel Mar 08 '22 at 00:10
  • @KarlKnechtel, I mean when I click enter after typing in my input the program to the first question it will not move on to the next question. – zackBYE344 Mar 08 '22 at 00:13
  • What do you mean by "will not move on"? Exactly what happens? How do you type in the input? What do you expect to happen instead? Did you press the Enter key after typing a number? (If not, how are you expecting the program to know that you are done typing the number?) – Karl Knechtel Mar 08 '22 at 00:14
  • 1
    Just change the `input.nextDouble();` line (the line where this is all by itself) to `input.nextLine();` and it should be fixed. See the linked answer for an explanation. – Idle_Mind Mar 08 '22 at 00:19
  • @KarlKnechtel. For my input, I typed in a double (6.99). I then clicked enter. When and after I type enter, the cursor moves downwards and it will keep on moving downwards until I type in a character or a string to then hit enter. – zackBYE344 Mar 08 '22 at 00:24

0 Answers0