Skip to content

Instantly share code, notes, and snippets.

@FrankDupree
Created April 1, 2017 19:54
Show Gist options
  • Save FrankDupree/6a90d2a776e55a7996dd45020175af32 to your computer and use it in GitHub Desktop.
Save FrankDupree/6a90d2a776e55a7996dd45020175af32 to your computer and use it in GitHub Desktop.
package com.codeniro.algorithms;
/**
*
* @author Frank Akogun
*/
public class Algo {
private final int[] arrayList = new int[20];
private final int arraySize = 10;
public void arrayGenerator(){
for (int i =0; i<arraySize; i++){
//generate random numbers between 10 and 19
arrayList[i]= (int) (Math.random()*10)+10;
}
}
public void printArray(){
System.out.println("----------");
for (int i=0; i<arraySize; i++){
System.out.print("| " + i +" | ");
System.out.println(arrayList[i] + " |");
System.out.println("----------");
}
}
public int getValueByIndex(int index){
if(index < arraySize){
return arrayList[index];
}
return 0;
}
public static void main(String[] args) {
Algo con = new Algo();
con.arrayGenerator();
con.printArray();
int index = 0;
int result = con.getValueByIndex(index);
System.out.println("Value at index "+ index + ": " + result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment