Created
November 11, 2019 16:29
-
-
Save Peters8090/4edbfbeb557a8a0ed48809089f29e343 to your computer and use it in GitHub Desktop.
[Computer programming homework] Write a program, in which we create an array of integers of length 10, which is initialized with any numbers from 1 to 100. The program has to print that array and the sum of all its elements.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Random; | |
public class ArraysAndLoops { | |
public static void main(String[] args) { | |
int[] array = new int[10]; | |
int arraySum = 0; | |
System.out.println("Array: "); | |
for(int i = 0; i < array.length; i++) | |
{ | |
array[i] = new Random().nextInt(100); | |
arraySum += array[i]; | |
System.out.println(array[i] + ","); | |
} | |
System.out.println("\nArray Sum: " + arraySum); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment