4 Replies - 339 Views - Last Post: 05 February 2012 - 10:40 AM Rate Topic: -----

Topic Sponsor:

#1 Ashang  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 05-February 12

Generate random number in 2D array

Posted 05 February 2012 - 10:03 AM

I am having trouble generating random numbers which randomly evaluate scores for each teacher assigned to a student with the fix number of teachers per student n=5.The total numbers of teachers and students equal to 10.

this is my code:
       Random rand=new Random();

       for(i=1; i<=10; i++ ){
           for(j=1; j<=10; j++){
                e[i][j]= rand.nextDouble();
                System.out.println("e[" + i + "][" + j + "] = " +e[i][j]);
            } 
        }


but at my code i just gernerated random numbers that every teachers evaluated every students. i don't know how to fix the number of teachers per student n=5. Could anyone pls help me?

Thanks in advance.

This post has been edited by smohd: 05 February 2012 - 10:04 AM
Reason for edit:: Code tags added. Please use [code] tags when posting codes


Is This A Good Question/Topic? 0
  • +

Replies To: Generate random number in 2D array

#2 smohd  Icon User is offline

  • Critical Section
  • member icon



Reputation: 1644
  • View blog
  • Posts: 4,126
  • Joined: 14-March 10

Re: Generate random number in 2D array

Posted 05 February 2012 - 10:11 AM

Quote

i don't know how to fix the number of teachers per student n=5. Could anyone pls help me?

I dont think if I understand what you are trying to do, but it looks like you want to have a 2D array of 10X5. Because if the rows represents students, then to have 5 teachers generated score means you need 5 columns and not 10. Is this what you meant? If not please elaborate more/
Was This Post Helpful? 0
  • +
  • -

#3 Ashang  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 05-February 12

Re: Generate random number in 2D array

Posted 05 February 2012 - 10:28 AM

View Postsmohd, on 05 February 2012 - 10:11 AM, said:

Quote

i don't know how to fix the number of teachers per student n=5. Could anyone pls help me?

I dont think if I understand what you are trying to do, but it looks like you want to have a 2D array of 10X5. Because if the rows represents students, then to have 5 teachers generated score means you need 5 columns and not 10. Is this what you meant? If not please elaborate more/


Sorry my english not good, in my code i need 10x10.But for each student was evaluated only 5 teachers, that mean i want to choose only 5 in 10 teachers that evaluate per one stedent.do untill 10 students.at my code below the frist loop is not work. can u advice me more?
.
This is my full code:

import java.util.Random;

public class Trandom1 {
    public static void main(String[] args){
        
        double[][] e= new double[10][10];
        int i,j;
        int [] m= new int[10];
        
        Random rand=new Random();
        
        for(j= 1; j<10; j++)
            for(i=1 ; i<10 ; i++) {
               if(e[i][j]>0.0)
                 m[j]++;
               System.out.println("m"+j+" = "+m[j]);
            }
        for(i=1; i<10; i++ ){
            for(j=1; j<10; j++){
                if(m[j]<=5){
                    e[i][j]= rand.nextDouble();
                    System.out.println("e[" + i + "][" + j + "] = " +e[i][j]);
                } 
            }
        }  
    }  
}

This post has been edited by smohd: 05 February 2012 - 10:39 AM
Reason for edit:: fixed code tags

Was This Post Helpful? 0
  • +
  • -

#4 CasiOo  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 433
  • View blog
  • Posts: 1,072
  • Joined: 05-April 11

Re: Generate random number in 2D array

Posted 05 February 2012 - 10:28 AM

Also you have to remember that array indexes start at 0 not 1
Was This Post Helpful? 0
  • +
  • -

#5 Ashang  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 05-February 12

Re: Generate random number in 2D array

Posted 05 February 2012 - 10:40 AM

View PostCasiOo, on 05 February 2012 - 10:28 AM, said:

Also you have to remember that array indexes start at 0 not 1


Yes, thanks sir. Is it possible to choose only 5 in 10 teachers that evaluate per one stedent.do untill 10 students?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1