黑马程序员技术交流社区
标题:
y<=(2*x+2)/3 这个不等式用java语言怎么输出和表达
[打印本页]
作者:
曾翀
时间:
2014-7-31 13:42
标题:
y<=(2*x+2)/3 这个不等式用java语言怎么输出和表达
y<=(2*x+2)/3 不等式用java怎么输出和表达。。。。y要取最大整数值。。。。
若用y=(2*x+2)/3;
可以吗? 谢谢
作者:
fantacyleo
时间:
2014-7-31 13:45
java.Math中的floor函数~~
作者:
fantacyleo
时间:
2014-7-31 13:48
int y = (int) floor((2 * x + 2) / 3);
作者:
icris
时间:
2014-7-31 14:02
如果 x 是 int ,那这样就行了,如果 x 是 double ,需要加上强制转换
int y =(int) ((2*x+2)/3);
作者:
dispensable
时间:
2014-7-31 14:12
class Demo
{
public static void main(String[] args)
{
//y <= (2*x+2)/3 不等式的值
System.out.println(printBoolean(3,4));
//y = (2*x+2)/3 y的最小整数
System.out.println(printFloor(3));
//y = (2*x+2)/3 y的最大整数
System.out.println(printCeil(3));
// y = (2*x+2)/3 默认情况下y的值
System.out.println(printDefault(3));
}
public static double printFloor(double x)
{
return Math.floor((2*x+2)/3);
}
public static double printCeil(double x)
{
return Math.ceil((2*x+2)/3);
}
public static boolean printBoolean(int x,int y)
{
return y<=(2*x+2)/3;
}
public static int printDefault(int x)
{
return (2*x+2)/3;
}
}
作者:
dispensable
时间:
2014-7-31 14:44
dispensable 发表于 2014-7-31 14:12
class Demo
{
public static void main(String[] args)
:L妈蛋啊,我以为你是新手呢,不然不会这么耐心……
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2