public class round {
public static void main(String[] args) {
double n = 1.7;
int result;
result = round(n);
System.out.println(result);
}
public static int round(double num) {
double n;
n = num - (int)num;
if ((int)(n*10) >= 5)
return (int)num+1;
else
return (int)num;
}
}
这段代码有什么问题么?
public static void main(String[] args) {
double n = 1.7;
int result;
result = round(n);
System.out.println(result);
}
public static int round(double num) {
double n;
n = num - (int)num;
if ((int)(n*10) >= 5)
return (int)num+1;
else
return (int)num;
}
}
这段代码有什么问题么?
result = Math.round(n)
那个必须是构造函数吧
一般类名都大写: public class Round
我也是刚学Java.
public static void main(String[] args) {
double n = 95877445555.01444554;
int result;
result = round(n);
System.out.println(result);
}
public static int round(double num) {
double n;
n = num - (int)num;
if ((int)(n*10) >= 5)
return (int)num+1;
else
return (int)num;
}}
LZ,你定的n足够大,那你的程序就不正确了.
return (int)(d + 0.5);
}
return (int)(d + 0.5);
}