java - How can differentiate between dividable by 2 and dividable by 4? -


i create program :

for 1st item , a, 2nd item , b, 3rd item , c , 4th item, d, 5th item , a, 6th item , b, 7 th item c , 8th item , d .... , on. pattern .

and , can differentiate odd , even, how can achieve above, 1 seem not work

            if ( position % 2 == 0) {                 if ( position % 4 == 0) {                     d();                 } else {                     b();                 }             } else {                 if ( position % 3 == 0) {                     c();                 } else {                     a();                 }             } 

thanks helping

position % 3 == 0 

should be

position % 4 == 3 

to select last of every 4 items. you'll need reorder function calls match description; think correct order a,c,d,b.

the code clearer using switch:

switch (position % 4) {     case 0: a(); break;     case 1: b(); break;     case 2: c(); break;     case 3: d(); break; } 

assuming whichever language you're using supports such construct.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -