Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.nami;
- import java.util.Arrays;
- public class Main {
- public Main() {
- //empty array with a length of 3
- int[] list = new int[3];
- //biggest possible number
- int maxNum = 100;
- //assigning random values between 0 and MAXNUM to the array
- for (int i = 0; i < list.length; i++)
- list[i] = (int) (Math.random() * maxNum);
- //printing the random array (LIST)
- System.out.println(Arrays.toString(list));
- //setting n to the first value of LIST
- int n = list[0];
- //looping through every element of LIST starting with the 2nd value
- for (int i = 1; i < list.length; i++)
- //if n is bigger than value from LIST with index I then set N to the value
- if (n > list[i])
- n = list[i];
- //print N (the smallest number)
- System.out.println(n);
- }
- public static void main(String[] args) {
- new Main();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment