Java #34: How to find the length of an Array & Turn Length into a Variable in Java

//Programmer: Akinwale Owi
//Company: Dagba Computers
//Program Purpose: Find the length of an array and turn that into a variable

package dagbacomputers;

/**
*
* @author Akin
*/

public class DagbaComputers {

/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
//Array that I am going to find the length of
String [] rappers = {“Future”, “Rick Ross”, “Jay-Z”};

//for loop that will print while rappers has elements left
for (int i = 0; i < rappers.length; i++)
{
//will print out the array vslue at current i position
System.out.println("Current Array Value: " + rappers[i]);
}//end of for loop

//turning the array length into an int
int aLength = rappers.length;

//Printing out aLength to test
System.out.println("Array length is " + aLength);

}//end of main
}//End of DagbaComputers Class

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: