Kevin321888999

Java: Random Number Generator With Arrays and Array Reversal

Oct 27th, 2022 (edited)
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | None | 0 0
  1. //This program creates an array of randomized numbers. It sets them in order, then reverses the order.
  2. import java.util.Random;
  3.  
  4. public class Main {
  5.     public static void main(String[] args) {
  6.         Banner();
  7.         Random Rand= new Random();
  8.         int num1= Rand.nextInt(10)+1;
  9.         int num2= Rand.nextInt(10)+1;
  10.         int num3= Rand.nextInt(10)+1 ;
  11.         int [] come={num1, num2, num3};
  12.         for(int i=0; i<3; i++){
  13.             System.out.println(come[i]);
  14.         }
  15.         System.out.println("Array length: "+ come.length);
  16.         System.out.println("Setting the array in the reverse order: ");
  17.         for(int i=2; i>-1;i--){
  18.             System.out.println(come[i]);
  19.         }
  20.     }
  21.     public static void Banner(){
  22.         System.out.println("Malachi Sor Random Numbers in a array\n-------------------\n");
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment