i want to make random numbers for x[row][col] that row =10 and col =10, but my problem is: how i fix random numbers of n[col]=5;

here is my code:

public static void main(String[] args){

        double[][] x= new double[10][10];
        int row,col;
        int n[]={0,0,0,0,0,0,0,0,0,0};

         for(row=0; row<10; row++ ){
            for(col=0; col<10; col++){
               if( n[col]==5){
                x[row][col]= (double) (Math.random());
                System.out.println("x[" + row + "][" + col + "] = "  x[row][col]); 
               }       
            }
        }
}

Why do you need array "n" in the first place?

Can't you assign numbers to the 2d array without it

Agree.You don't need the if statement.
Also , your if statement is never evaluating to true

Why do you need array "n" in the first place?

Can't you assign numbers to the 2d array without it

i don't know how do i do it, my popsoe is x[row][col] is the score that teacher evaluated students, and i want to generate random score to students but each student should had evluated only 5 teacher so i use n[col]=5. pls help me!!!!!!

km2011, if i understand there should be 10 students with 5 scores each correct?

in this case you would not need 10 columns , also for your "for" statements you probably dont want to hardcode the upper limits, you should go untill "x.lenght" and "x[row].length" instead.

as for your populating to work DJSAN was right, drop the if statement.

each student should had evluated only 5 teacher so i use n[col]=5.

What I understand by this is that you want every student should be evaluated only 5 times.Is this the case? If so , take a counter and increment it after each evaluation. Your if statement will now check if the counter <= 5, only then evaluation will be done. Also don't forget to reset the counter i.e. counter=0 for every new student evaluation. Let me know if I have misinterpreted your problem as I am not quite able to understand what you exactly want to do.

What I understand by this is that you want every student should be evaluated only 5 times.Is this the case? If so , take a counter and increment it after each evaluation. Your if statement will now check if the counter <= 5, only then evaluation will be done. Also don't forget to reset the counter i.e. counter=0 for every new student evaluation. Let me know if I have misinterpreted your problem as I am not quite able to understand what you exactly want to do.

Thanks for all answers. i'll try it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.