Good evening everyone ,
I am writing this post to ask you guys if you can help me on this very basic program .
I am still a student in programming and a beginner with arrays and i am asked to create a program that creates random elements of arrays between 0 and 9 , and inside every box of these arrays a random number between 0 and 100 and finally to calculate the sum of these numbers , example
6 random elements of an array are generated , inside each one of these elements a certain value is created , then i shall add these value and print the value.
Now as i said i am still a beginner in java so i know this program is messed up but at least i tried i hope you guys can help me , thank you :
public class arrays { public static void main(String[] args) { double x = 0 ; double [] numbers = {x*(Math.random()*10)}; double result = sumLessThanAverage(numbers); System.out.println(result); } public static double sumLessThanAverage(double[]a){ double x = 0; double sum = 0; double count=0; x = x * Math.random()*101; for ( int i = 0 ; i<= a.length-1 ; i++){ a[i] = x; sum += x; x = x * Math.random()*101; count ++; } return sum; } }