Adding early CS challenge solutions

This commit is contained in:
2024-06-28 17:02:20 -04:00
parent 1c2266f4c5
commit 79772e0ee0
9 changed files with 343 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
import java.util.Random;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Random random = new Random();
Scanner scan = new Scanner(System.in);
System.out.print("Number of random values to create: ");
int numberToRandomize = scan.nextInt();
scan.close();
double sum = 0;
for(int i = 0; i < numberToRandomize; i++) {
double randomNumber = random.nextDouble();
System.out.println("Random Number " + (i + 1) + ": " + randomNumber);
sum += randomNumber;
}
System.out.println("Sum = " + sum);
System.out.println("Average = " + (sum / numberToRandomize));
}
}