• Skip to main content
  • Skip to primary sidebar

Founder at work

Master the skills to create and launch your next SaaS company

  • About Me
  • Reviews
  • Resources
  • Community
  • Contact
  • Lessons
  • Series
  • Search
  • Login

How to create arrays in java?

November 12, 2012 by Rick Hernandez Leave a Comment

When working with arrays you want to think about them like a shelf you can take things in and out of them and see what they store. Arrays can be declared by different types from int to strings although int arrays get an initial value of zero so in this example i create an array of the size of 15, that starts off from the number 0 and moves up to shelf 14 making it size 15, you see we always count starting at zero. I create the header with the following notations to get a nice pretty layout of the data, as follows %s%8s\n, look at the this for modulus definition Entering the for loop structure where it creates a variable of c and sets it to zero, then compares c to the arrays length and iterates threw the loop until it reaches the size of the array and exits, this is controlled looping.

public class Program
{
    public static void main(String args[]) 
    {
        int [] array; // creates an array 
        array = new int[15]; // sets the value of the array
        System.out.printf("%s%8s\n", "indexx", "value"); // prints out the Header 

         // sets a value for c and enter the for loop pro the size of the 
                    array denoting .length 
        for (int c= 0; c < array.length; c++) 
        {
            System.out.printf("%5d%8d\n", c, array[c]); 
        }

    }
}
Rick Hernandez

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

Share this:

  • Click to share on Twitter (Opens in new window)
  • Click to share on Facebook (Opens in new window)

Related

Filed Under: Java, Programming

Primary Sidebar

Learn How To Take Your Idea And Convert It Into An App From Scratch Even If You Have Never Written A Single Line Of Code.

  • How to Find Your Next Great App Idea
  • The Secret To Getting PAID To Build Your Own App
  • How To Create Your App (SaaS, Mobile, VR, AR, Game)
  • How To Monetize Your Apps
Learn More
4.82 Ratings

Copyright © 2025 · JSecademy Blog Theme on Genesis Framework · WordPress · Log in