473,396 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Array elements as counters

Expand|Select|Wrap|Line Numbers
  1. import java.util.Random;
  2. public class apples {
  3.  
  4.     public static void main(String args[]){
  5.         Random rand= new Random();
  6.         int freq[]=new int[7];
  7.  
  8.         for(int roll=1;roll<1000;roll++){
  9.             int index = 1+rand.nextInt(6);
  10.             int f = freq[index];
  11.             ++f;
  12.             freq[index] = f;
  13.         }
  14.  
  15.         System.out.println("Face \tFrequency");
  16.  
  17.         for(int face=1;face<freq.length;face++){
  18.             System.out.println(face+"       "+freq[face]);
  19.         }
  20.     }
  21. }
Please can someone explain the first (for loop)of the program...with an appropriate example will be really helpful.
Thank You.
Jan 2 '15 #1
0 1202

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Herrcho | last post by:
in K&R Chapter 6.3 it mentions two methods to calculate NKEYS. and points out the first one which is to terminate the list of initializers with a null pointer, then loop along keytab until the...
3
by: trevorelbourne | last post by:
Hi, I am having trouble accessing the elements of an array using reflection. This is the code I am having trouble with: FieldInfo Fields = Obj.GetType().GetFields(); foreach (FieldInfo fi in...
8
by: ljlevend2 | last post by:
If a property's type is an array and the property is exposed in a PropertyGrid, then the property can be expanded so that the user can view and edit the array elements. But, I've noticed that if...
24
by: RyanTaylor | last post by:
I have a final coming up later this week in my beginning Java class and my prof has decided to give us possible Javascript code we may have to write. Problem is, we didn't really cover JS and what...
6
by: Kumar | last post by:
How should I declare the array elements being half word? and the array elements of the type byte in C?? Please help Kumar
8
by: SP | last post by:
The following code crashes after I add the two nested FOR loops at the end, I am starting to learn about pointers and would like to understand what I'm doing wrong. I think the problem is the way...
14
by: dan | last post by:
I would like to have the preprocessor automatically generate the number of array elements requested. Each element is zero. The elements get pasted into a larger array. The other elements may be...
1
by: procris99 | last post by:
I'm having ALOT of trouble understanding this (C++)..and i don't think i'm even close to getting this right. Please help. The problem reads as follows: Use a one dimensional array to solve. A...
2
by: awaisworld13 | last post by:
I want to write a program which take input and save the poistions of the array elements in another array. let if i enter an array A= 4 A=1 A=2 A=3 now the output array will hold 1 2 3
1
by: eran yurman | last post by:
H, I need to call an API with the follwoing prototype: unsigned long CountDevices (BYTE *p_deviceSize,BYTE *p_device ); I have no knowledge of the content of the API function itself but...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.