-2
/**
* Write a description of class GUI here.
*
* @author (your name)
* @version (a version number or a date)
*/
import java.util.*;
public class GUI
{
// instance variables - replace the example below with your own
public static void main(String [] args){
Scanner r = new Scanner(System.in);
int x;
int y;
int z;
System.out.println("x");
x = r.nextInt();
System.out.println("y");
y = r.nextInt();
System.out.println("z");
z = r.nextInt();
double t = (x+y+z)/3;
System.out.println("result " + t);
}
}
你好,以上是我的代码。
我故意把它做成int x,y,z来测试程序。
当我输入例如(当运行程序时):$ x = 1,1,3 $它总是回答答案!为什么是这样?
整数除法 – Reimeus
因为你转换为加倍您的最终结果, – user902383
'INT/INT = int'但是'(双)INT/INT = double' –