我的编程课程希望我有这样的结局:
public class Nelilaskin {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
System.out.println("Enter the first number!");
int first = Integer.valueOf(reader.nextLine());
System.out.println("Enter the second number!");
int second = Integer.valueOf(reader.nextLine());
int plus = (first + second);
int minus = (first - second);
int multi = (first * second);
double division = (first / second * 1.0);
System.out.println(first + " + " + second + " = " + plus);
System.out.println(first + " - " + second + " = " + minus);
System.out.println(first + " * " + second + " = " + multi);
System.out.println(first + " / " + second + " = " + division);
}
}
问题来源:Stack Overflow
这是因为您要分割两个int值,请尝试将其中至少一个转换为double。
double division = (double)first / (double)second ;
回答来源:Stack Overflow
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。