How to Add strings to this code?
Hi, I already have the code below but i have to do the following with it. I am making a Unit convertor program where I can convert CM to Inch and Fahrenheit to Celsius in same program.
I want to use strings. For example:- User will have different options for the unit converter they want to use.
Such as:
Option A: cm to inch
Option B: Fahrenheit to Celsius
If user enters letter “B” than program will convert Fahrenheit to
Celsius. User will be asked to enter a value in Fahrenheit and once the
value is entered it will convert it to Celsius.
Here is the code
CM to Inch
import java.util.Scanner;
public class FinalProject {
public static void main (String args[]){
// 2.54cm is 1 inch
Scanner cm = new Scanner(System.in); //Get INPUT from pc-Keyboard
System.out.println(“Enter the CM:”); // Write input
//double
double centimeters = cm.nextDouble();
double inches = centimeters/2.54;
System.out.println(inches + ” Inch Is ” + centimeters + ” centimeters”);
}
}
Fahrenheit to Celsius
double celsius=0, fahrenheit=0;
Scanner scan = new Scanner(System.in);
System.out.println(“Enter the amount of Fahrenheit to be converted: “);
fahrenheit = scan.nextDouble();
celsius = (fahrenheit-32)*5/9;
System.out.println(“The entered amount of Fahrenheit is equal to ” + celsius + ” degrees Celsius.”);
}
}


0 comments