The only difference in this peace of code is that instead of an array that has a fixed size, its an array that is pre defined size. What i mean to say in simple terms is that I have created 10 shelf’s to store my beautiful numbers, so shelf 0 stores 2 and shelf one stores 7, ….. so on till shelf 10 and that’s where 7 lives. So this type of arrays are great when you actually know the number of shelf’s and what will be stored inside of them.
public class Program { public static void main(String args[]) { // initialize list int [] array = {2,7,4,8,5,4,0,0,0,7}; System.out.printf("%s%8s\n", "Index", "Value"); for (int c= 0; c < array.length; c++) { System.out.printf("%5d%8d\n", c, array[c]); } } }
I always had a passion for the field of STEM (Science, Technology, Engineering, and Math) and I knew I wanted to do something to make a difference in the world. I just didn’t know where to start. I was an immigrant in a new country, grew up in a tough environment, and wasn’t sure how… Read More