PDA

View Full Version : Boolean Problem


jakie8
09-14-2008, 03:44 PM
This is Java ,but maybe it is similar?

// This method returns true if the average of the three parameters is the difference between
// @param three and @param one; it returns false in all other cases.
public static boolean weirdAvg(int one, int two, int three)
{
boolean boo = one + two + three % 3 += three + one;
return boo;
}

The 5th line is incorrect somehow. Any ideas?

coothead
09-14-2008, 05:17 PM
Hi there jakie8,

does this help...

<script type="text/javascript">

num=348;
num=num.toString();

if((
parseFloat(num.charAt(0))+
parseFloat(num.charAt(1))+
parseFloat(num.charAt(2)))/num.length==
Math.abs(
parseFloat(num.charAt(2))-
parseFloat(num.charAt(0))
)) {
alert(true);
}
else {
alert(false);
}

</script>

Jon Hanlon
09-15-2008, 06:14 PM
public static boolean weirdAvg(int one, int two, int three)
{
boolean boo = (one + two + three) / 3 == (three - one);
return boo;
}

in Javascript:

function weirdAvg(one, two, three)
{
var boo = return ((one + two + three) / 3 == (three - one));
return boo;
}