Hi, how do u calculate the sum of the numbers in the array?
Thanks!
By adding each element in the array.
how do u add the elements?
this is my program
import java.util.Scanner;
public class RandomNumbers
{
public static void main(String [] args)
{
Scanner scan= new Scanner(System.in);
int pos, value;
System.out.println("Enter value of numbers to generate(0-100): ");
value=scan.nextInt();
while (value<0 || value>100)
{
System.out.println("Please enter value again (0-100): ");
}
double[]random =new double[value];
for (pos=0; pos< value; pos++)
{
random[pos]=Math.random()*1000.0 + 17.5;
}
System.out.println("Here are the random numbers: ");
for (pos=0; pos<value; pos++)
System.out.println(random[pos]);
}
}
i need to generate the sum of the random numbers.
//pseudocode
for (lowest array value to highest array value)
{
add array value to total sum
}
double Total = 0;
int i;
for (i=0; i< 10; i++)
{
double rdNumber = Math.random() *1000.0 + 17.5;
Total+=rdNumber;
}
System.out.println("Sum: " +Total );
Sample loop to accumulate total value.