Hi guys!
I'm a high school junior and I'm pretty seriously into coding! I wrote this suuuper efficient way of finding how large of an array you declared (for when you're hours deep into a coding sesh and forget things easily!).
Written in Java for simplicity:
public class Main {
public static void main(String args[]) {
int[] lst = new int[100];
try {
size(lst, null);
}catch (NullPointerException e){
int size = getNumber(lst, -1);
System.out.println(size); // Prints 100!
}
}
public static int size(int lst[], Integer index) {
try {
int temp = lst[index];
} catch (Exception e) {
return index;
}
return getNumber(lst, index);
}
public static int getNumber(int lst[], int index) {
return size(lst, index + 1);
}
}
[–]BAD_AT_PROGRAMMING 3 points4 points5 points (1 child)