d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Ez Question > Java
Add Reply New Topic New Poll
Member
Posts: 5,167
Joined: Nov 23 2006
Gold: 11.01
Mar 6 2015 08:33pm
Write this in Java a simpler way. Navigating through array of objects to see if % 5 then print Fizz if %20 then print Bizz.

Code


for(int j=0; j<bizz.length; j++){
if(bizz[j].getNum() % 5 == 0 && !(bizz[j].getNum() % 20 == 0)){
System.out.println("Fizz");
}
else if(bizz[j].getNum() % 20 == 0){
System.out.println("Bizz");
}
}

Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Mar 6 2015 09:05pm
Code
System.out.println("Stop doing drugs, OP.");
Member
Posts: 5,167
Joined: Nov 23 2006
Gold: 11.01
Mar 6 2015 09:07pm
Quote (Eep @ Mar 6 2015 10:05pm)
Code
System.out.println("Stop doing drugs, OP.");


Coincidentally I'm a little high on pain meds. Damn wisdom teeth >.>

But for realzzzzz am I derping or is there a simpler way to write this? Buddy asked me and my brain doesn't work very well on these.

This post was edited by HoneyBadger on Mar 6 2015 09:10pm
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Mar 6 2015 10:02pm
Quote (HoneyBadger @ Mar 6 2015 10:07pm)
Coincidentally I'm a little high on pain meds. Damn wisdom teeth >.>

But for realzzzzz am I derping or is there a simpler way to write this? Buddy asked me and my brain doesn't work very well on these.


does it matter?
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Mar 7 2015 04:15pm
flip the conditionals to avoid the duplicate check
Member
Posts: 5,167
Joined: Nov 23 2006
Gold: 11.01
Mar 7 2015 04:36pm
Quote (carteblanche @ Mar 7 2015 05:15pm)
flip the conditionals to avoid the duplicate check


That's what it was! I can't believe I didn't remember that -.- checking % 20 first eliminates the need for the !%20 in the second conditional -.-
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll