问题描述
- 请问这个代码应该如何写,完全没有思路啊,求解
-
这个怎么写代码啊,一点思路都没有,怎么办啊,求解????????开发思路">
解决方案
借鉴一下,改改。
public static void main(String[] args) {
// TODO Auto-generated method stub
Runtime runtime = Runtime.getRuntime();
System.out.println("占用内存:"
+ (runtime.totalMemory() - runtime.freeMemory()));
long timeStamp = System.currentTimeMillis();
Scanner scanner = new Scanner(System.in);
while (scanner.hasNextInt()) {
int tem = scanner.nextInt();
System.out.println("输入的华氏温度是:" + tem);
Integer temperature = (tem - 32) * 5 / 9;
System.out.println("输出的摄氏温度是:" + temperature);
System.out.println("消耗时间(包含输入):"
+ (System.currentTimeMillis() - timeStamp) + "毫秒");
}
scanner.close();
}
解决方案二:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Test {
private static int F;
public static void main(String[] args) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
F = Integer.parseInt(br.readLine());
} catch (NumberFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if(br != null) {
try {
br.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
System.out.println((int)((F-32)*5/9));
}
}