Hi i m having problem...
i want to give each random number to each month..
but it gives erros

``````public class a
{
public static void main(String[] args)
{
float average = 0f;
String[] Year = {"Jan","Feb","Mar","Apr","May","Apr"};
int[] values = new int[5];

for(int i=0; i<values.length; i++)
{
values[i] = (int)(100*Math.random());
average+=values[i];

}
average=average/values.length;

for(int j=0; j<Year.length; j++)
{
Year[j] = (values[j]);
}

System.out.println(average);

}
}``````

Error is
C:\Users\dell\Desktop\a.java:20: incompatible types
found : int
required: java.lang.String
Year[j] = (values[j]);
^
1 error

Tool completed with exit code 1

Well, yes, Year is an array of 6 Strings, values is an array of 5 ints. What exactly do you want to do? It looks like you are trying to overwrite the initial String values with ramdom ints - does this make sense? Anyway, you can't put ints into an array of Strings, and you can't get the 6th value from an array of length 5.

Well, yes, Year is an array of 6 Strings, values is an array of 5 ints. What exactly do you want to do? It looks like you are trying to overwrite the initial String values with ramdom ints - does this make sense? Anyway, you can't put ints into an array of Strings, and you can't get the 6th value from an array of length 5.

Sir,actually i m learning java and its a exercise practice..the question is..
create an array of string variables and initialize the array with the name of the months from jan to dec.create an array containing 12 random decimal values.dsplay the names of each month alng with the corressponding decimal value.calculate and display the average of the 12 decimal value...

this i want to do it. :(

It looks like you are 90% done. There's no requirement to copy the decimal values to the months, so your lines 18-22 are not needed. Take them out and see what happens next.

Also what you are referring to is not an Array at all. Many languages say an array is a key => value which is what you are saying you want. In Java there is a distinction between an Array (list) and a Map (Array in other languages, so on). So if you want a Map try using a standard HashMap.