java - How to reduce if statements -


the program below functions necessary how reduce amount of if statements. have been told if function contains 2 or more if statements doing wrong. suggestions? i've tried using switch statements hasn't worked because case can't boolean.

for(int = 1; < 100; i++)         {         if(i % 10 == 3)          {             system.out.println("fizz" + "(" + + ") 3%10");         }          if(i / 10 == 3)         {             system.out.println("fizz" + "(" + + ") 3/10");         }           if(i % 10 == 5)          {             system.out.println("buzz" + "(" + + ") 5%10");         }          if(i / 10 == 5)         {             system.out.println("fizz" + "(" + + ") 5/10");         }          if(i / 10 == 7)         {             system.out.println("fizz" + "(" + + ") 7/10");         }          if(i%10 == 7)         {             system.out.println("woof" + "(" + + ") 7%10");         }          if(i % 3 == 0)         {             system.out.println("fizz" + "(" + + ") 3%==0");         }          if(i % 5 == 0)         {             system.out.println("buzz" + "(" + + ")5%==0");         }          if(i % 7 == 0)         {             system.out.println("woof" + "(" + + ")7%==0");             }          if( (i % 7 !=0 ) && (i % 3 !=0 ) && (i % 5 !=0 )                 && (i % 10 !=3) && (i % 10 !=5 ) && (i%10 !=7 ) )             system.out.println(i);     } 

how creating method cases:

 public void printifmod(int value, int mod){        if (value % 10 == mod)           system.out.println(...);  }   public void printifdiv(int value, int div){        if (value / 10 == div)           system.out.println(...);  } 

then instead of bunch of if have set of calls the 2 methods. might create single method calls both of above.

 public void printif(int value, int div){       printifmod(value, div);       printifdiv(value, div);  }   for(int = 1; < 100; i++) {       printif(i, 3);       printif(i, 5);       ....  } 

in above code number of ifs less of issue me amount of repeated code.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -