save a fix in java

0

Good evening friends, I'm new to this, they let me make a code from the ulam series (you give a number and if a pair is divided by 2 and if odd it is multiplied by 3 and 1 is added, so until you reach 1 that would be the end) but they ask me to keep the numbers in an arrangement. the lines are generated by a random (1 to 5) while the columns must be 70 although not all are used. The number to use is also a random (from 2 to 209 I get it if I print it in a print but when I try to save it in the array it marks me error ... I leave the code I have waiting for you to help me ...

Random ra=new Random();

int  mat [ ] [ ];
int  ren,col = 0,rrn,r=0,re,c=0;
boolean vr=false;

rrn=2+ra.nextInt(4);
  mat = new int [c ]  [ r ];

  for(ren=0;ren<rrn;ren++)
      {

           for(col=0;vr!=true;col++)
           {
                 re=2+ra.nextInt(19);
                 mat [ren] [col]=re;
                 while(re!=1)
                       { 
                             if(re%2!=0)
                              {
                               re=(re*3)+1;

                              }//fin del if
                            else
                             {
                               re=re/2;

                             }//fin del else
                             mat[ren] [col]=re;
                       }// fin del while 
                 vr=true;
           }//fin del for col
           vr=false;
      }//fin del for ren
    System.out.println( mat [ren][col]+" : ");
    
asked by c.moy6 14.05.2017 в 08:42
source

1 answer

0

I can not comment, but for now I see that the error would be ArrayIndexBoundsException (?) Post it if so.

mat = new int [c ]  [ r ];

You are creating the Array at 0 - 0 since col = 0 and r = 0. Therefore when you try to take the second round

mat [ren] [col]=re; // No existe ya has creado el array solo para 0 - 0

Post the error if you can. Thanks!

    
answered by 14.05.2017 в 13:21