1
\$\begingroup\$

This works in my Eclipse, but I think there is a better way to do it.

public static void main(String args[]) {

       for(int i = 1; i < 101; i++)
       {
           if(i%3 == 0)
           {
           System.out.println("repetitive of 3");
           }

           else if(i%5 == 0)
           {
           System.out.println("repetitive of 5");
           }

           else{
               System.out.println(i);
           }


       }


   }

}
\$\endgroup\$
4
  • \$\begingroup\$ Please see my notes on @UwePlonus answer for details of the edits. \$\endgroup\$
    – rolfl
    Oct 2 '14 at 13:16
  • 2
    \$\begingroup\$ Technically 3 and 5 are not repetitions of 3 and 5. You should consider this case or use a different output. \$\endgroup\$
    – wei2912
    Oct 2 '14 at 13:55
  • 3
    \$\begingroup\$ Are you looking for multiples of 3 and 5? That's what your code does, at least. \$\endgroup\$
    – Bergi
    Oct 2 '14 at 19:26
  • 8
    \$\begingroup\$ FizzBuzz! \$\endgroup\$
    – blahdiblah
    Oct 2 '14 at 20:26