Array elements as counters

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • abhishekphukan
    New Member
    • Jul 2014
    • 34

    Array elements as counters

    Code:
    import java.util.Random;
    public class apples {
    	
    	public static void main(String args[]){
    		Random rand= new Random();
    		int freq[]=new int[7];
    		
    		for(int roll=1;roll<1000;roll++){
    			int index = 1+rand.nextInt(6);
    			int f = freq[index];
    			++f;
    			freq[index] = f;
    		}
    		
    		System.out.println("Face \tFrequency");
    		
    		for(int face=1;face<freq.length;face++){
    			System.out.println(face+"       "+freq[face]);
    		}
    	}
    }
    Please can someone explain the first (for loop)of the program...with an appropriate example will be really helpful.
    Thank You.
    Last edited by Rabbit; Jan 2 '15, 05:22 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
Working...