public class Temps
{
public static void main (String[] args)
{
// Define constants
final double celsius;
final double fahrenheit;
// Display prompt for temperature in degrees Farhenheit or Celsius
System.out.print("Please enter the temperature in degrees: ");
// Read temperature
Scanner in = new Scanner(System.in);
double temp = in.nextDouble();
// Display prompt for character that denotes type of temperature
System.out.print("Enter F for Farhenheit or C for Celsius: ");
// Read character denoting type of temperature
String type = in.next();
// Compute and print Celsius or Farhenheit equivalent
if(type.equalsIgnoreCase("f"))
fahrenheit = (9/5)celsius + 32);
System.out.println(temp + " Farhenheit = " + result + " Celsius.");
if(type.equalsIgnoreCase("c"))
celsius = (5/9)(fahrenheit - 32.0)
System.out.println(temp + " Celsius = " + result + " Fahrenheit.");
}
}
This post has been edited by rbk3ai: 30 September 2012 - 12:26 PM

New Topic/Question
Reply



MultiQuote





|