+ 2

Boolean and conditional operator

Hi! I have a code that works perfectly and do what it suppose to do, but the problem is, that it requires a boolean to be assigned to user's input and a conditional operator in println(). Many points were deducted from my grade for this, and I'm trying to figure out, how and where I was supposed to put boolean and for what purpose I have to use a conditional operator. My code prompts user to enter an even multiple of 13 more than 100 and evaluates it. Any ideas? Here is my code: https://code.sololearn.com/c1bIG5ws8cB4 Thank you in advance!

25th Jan 2018, 10:20 PM
DIY Mods
DIY Mods - avatar
6 ответов
+ 3
you could do something like: int input = kbdIn.nextInt(); boolean isEvanMultiple = (input % 2 == 0 && input % 13 == 0 && input ≥ 100); System.out.println(isEvanMultiple ? "other factor is " + input/13.0 : "that's not a multiple of 13 above 100");
25th Jan 2018, 10:45 PM
Jeremy
Jeremy - avatar
+ 1
I'm not sure exactly, something you could do is boolean isEven = kbdIn.nextDouble() % 2 == 0; and then the of statement would read if (isEven) // code... something along those lines. Obviously add more conditions to fulfil your criteria. Careful though, because this way you won't have access to the actual number, so be sure to store it first. On another note, your code says it's looking for an even multiple of 13 but the if statement has all OR operators, so if any one condition is true the statement will pass - try entering 2 or 13. These should be && based on your comments.
25th Jan 2018, 10:34 PM
Dan Walker
Dan Walker - avatar
+ 1
there is a boolean in what i wrote
25th Jan 2018, 10:52 PM
Jeremy
Jeremy - avatar
0
Great answer! Thank you very much! Just corrected ||. If you have a minute, can you please try to add boolean and cond. operator to my code, because I'm fighting with it entire day and can't figure out how to do it. I know it's a easy/silly stuff, but I'm a beginner and need some help from experienced coders. Thanks again!
25th Jan 2018, 10:41 PM
DIY Mods
DIY Mods - avatar
0
Thank you, Jeremy! Good idea to remove one variable, but I still can't fit there a boolean. Just updated my code
25th Jan 2018, 10:50 PM
DIY Mods
DIY Mods - avatar
0
I see, but I can't fit it in the code properly
26th Jan 2018, 3:17 AM
DIY Mods
DIY Mods - avatar