import java.util.Scanner; |
/** |
* 摄氏温度与华氏温度转换 |
* |
*/ |
public class SwitchTest { |
public static void main(String[] args) { |
Scanner sc = new Scanner(System.in); |
while ( true ) { |
System.out.println( "请输入要转换的温度类型:C(C转F) 或 F(F转C)" ); |
String s = sc.next().trim(); |
if ( "c" .equalsIgnoreCase(s)) { |
// 做摄氏向华摄的转换 |
System.out.println( "请输入要转换摄氏的温度:.." ); |
double db = sc.nextDouble(); |
double db2 = (db * 9 / 5 ) + 32 ; |
System.out.println( "对应的华氏温度:" + db2 + "F" ); |
} else if ( "f" .equalsIgnoreCase(s)) { |
// 做华摄向摄氏的转换 |
System.out.println( "请输入要转换华氏的温度:.." ); |
double db = sc.nextDouble(); |
double db2 = (db - 32 ) * 5 / 9 ; |
System.out.println( "对应的摄氏温度:" + Math.round(db2) + "C" ); |
} else if ( "exit" .equalsIgnoreCase(s)) { |
break ; |
} |
} |
} |
} |