Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Populate an 1D Array with odd Numbers

$
0
0
Hi there, I'm having trouble trying to fill a 1D array with odd numbers from 1 to 12 using loops. thanks in advance =) this is what i have so far:


  
        int[] odd = new int[6];
        odd[0]=1;

       for(int j=0;j<6;j++)
        {
          for ( int i=0;i<12;i++)
           {
            if(i%2==0)
            even[j]=2 * j + 1; break;
           }
         }
    for (int i:odd)
      System.out.println(i);
      




Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>