import java.util.Scanner;
public class Demo1{
public static void main(String[]args){
int temp;
int result;
Scanner sc=new Scanner(System.in);
temp=sc.nextlnt();
result=(temp-32)*5/9;
}
}
那么你是想解决什么问题呢?
这样写的话,temp是int,参与运算的常量也全是int,它会做整数除法。如果你想得到小数输出的话,result得是double型,还得把32改成32.0。
而且,你的程序根本没写输出啊,System.out.println
你的代码还有一个致命问题:是nextInt(大写I)而不是nextlnt(小写l)。写代码一定要仔细思考每个函数是什么意思啊,这种错误一看就是照着写代码看错了。Int是整数的意思,lnt则没有任何意义啊。
import java.util.Scanner; public class Demo1{ public static void main(String[]args){ int temp; int result; Scanner sc=new Scanner(System.in); System.out.println("请输入一个整数:"); temp=sc.nextInt(); result=(temp-32)*5/9; System.out.println(result); } }
nextInt ===> I 是大写的i 不是小写的L
兄弟,换个ide吧!