I'm writing a program in Java that does temperature conversion, but running into an issue.
import java.util.*;
public class TempCon2 {
public static void main (String[] args) {
double f,c,temp;
char ch,op;
Scanner sc = new Scanner(System.in);
System.out.println("This program converts temperatures from Fahrenheit to Celsius and vica versa.");
do {
System.out.print("Please enter your temperature: ");
temp = sc.nextDouble();
System.out.print("Please enter the units (F/C): ");
ch = sc.next().charAt(0);
if(ch=='F') {
c=(temp-32)*5/9;
System.out.println("\nThe temperature of " + temp + " degrees Fahrenheit is equivalent to " + c + " degrees Celsius!"); }
else if(ch=='C') {
f=(temp*9/5)+32;
System.out.println("\n The temperature of " + temp + " degrees Celsius is equivalent to " + f + " degrees Fahrenheit!"); }
System.out.print("Do you wish to do another conversion? (Y/N): ");
op=sc.next().charAt(0);
System.out.println();
if(op=='N' || op=='n') {
break; }
}while((op=='Y' || op=='y'));
System.out.println("Thank you, Goodbye");
}
}
I want to be able to check when the user inputs their temperature if its a number, and if not it returns a message that says " 'user input' is not a number. Please enter a number". As well as when it asks for the units that if you enter anything other than "F" or "C" it does the same as the number one.