需要帮助编写简单的if语句涉及绝对值而不使用Math.abs() [英] Need help writing simple if statement involving absolute value without using Math.abs()

查看:234
本文介绍了需要帮助编写简单的if语句涉及绝对值而不使用Math.abs()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的入门Java课程做练习测试。它填补了空白,我们的老师希望我们为各种问题编写简单的if语句。我难倒的那个是下面的。我们不应该使用Math.abs();我们显然只应该编写一行代码。





3. x绝对值小于100

如果()





任何关于如何实现这一目标的提示都将不胜感激!



谢谢,

马特

Hi, I''m doing a practice test for my Introductory Java class. It''s fill in the blank and our teacher wants us to write a simple if statement for various problems. The one I''m stumped with is below. We aren''t supposed to use Math.abs(); and we''re apparently only supposed to write one line of code.


3. x absolute value is less than 100
if ( )


any hints on how to accomplish this would be appreciated!

Thank you,
Matt

推荐答案

你不必使用数学。您可以简单地写:



You don''t have to use Math. You can simply write:

if (x*x < 10000) //...





简单,不是吗?



- SA


非常简单的尝试

Very simply try
if (x>100 || x < -100)
{
  return true;
}
else
{
  return false;
}


这篇关于需要帮助编写简单的if语句涉及绝对值而不使用Math.abs()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆