Java Two-Dimensional Array

The arrays we used so far were uniform series arrays, where all the array elements stay in a simple list, like in a column. This is the structure of one-dimensional array, where all elements fit in one list (life is very simple). But sometimes, you may need to divide the list in a delimited sections.

     For example, if you have an array of STUDENTs, and you want to add GRADEs on part on that array, and also want to include PARENTs on that array. What do we do? Well, instead of creating second array, we can add another dimension with the existing array (life is still simple). This is the idea of a multi-dimensional array. So, we can say, multi-dimensional array is a series of arrays where each array holds its own sub-array. We talked about one-dimensional arrays in our last post, and now we will walk with two-dimensional arrays and even three-dimensional arrays. Ok friends, let’s break the wall between multi-dimensional arrays and us. First take a look at this image..

Best Programmer Joke _ int page[1];

1. Definition 
Programmer Shirt

Java Array

We know that variables are used to store data in a Java program. We also know that each variable can store not more than one data item. So, what do we do if we need to store a large number of data items, say 50. Well, we can use 50 variables, one for each of the 50 data items, but we need to write 50 lines of code for setting up these variables, or we can use ARRAYs. Which will need just a single line. Most real-world programs handle vast amount of data. An array with loops can relatively handle a vast amount of data.

     An array is an object that is used to store a list of values, all of which have the same data type (Check Two Dimensional Array for complex data type). An array is a reference data type just like class. It is made of an attached block of memory. This memory space is also divided by CELLs, which hold a value. Sometimes the cells of an array are called SLOTs. Below is a picture of an array.

Array Elements
Array Elements

Nth Fibonacci number using Java Recursion

There are certain problems that just make sense to solve using Java Recursion. Demonstrating Fibonacci Series is one of them. Let’s take a look at something called Fibonacci series. Here are the first few numbers of this series:
0, 1, 1, 2, 3, 5, 8, 13, 21…

     Now stop reading and try to figure out what’s going on or let’s walk thru the sequence together and see how it works:
To obtain the sequence, we start with 0 and 1 after which every number is the sum of the previous two numbers. 
For example, the first two numbers will be 0 and 1
0, 1
For the next number, we add the previous two numbers 0 and 1 which gives one. 
0, 1, 1
The next number would be 1 + 1 = 2 
0, 1, 1, 2 
Now, the next number would be 1 + 2 = 3 
0, 1, 1, 2, 3

Russian Peasant Multiplication

This method involves a process of halving and doubling, which reduces one factor to powers of two and uses the distributive property of multiplication over addition to calculate a product.


Multiplication:     
                              25                    37
                              12                    74
                              6                      148
                              3                      296
                              1                      592
                            -------------------------           Therefore, 37 + 296 + 592 = 925
                                                      925                              ( 25 x 37 = 925 )

Just some of my favorite Philosoraptors

Originally shared by Not Adela
Philosoraptors
Philosoraptors

Java Recursion Method

This is one of my favorite part of java programming. It is little bit complex with its function. And obviously, it will turn to be a fun part, if you get it. It is called Java Recursion.
So what is Java Recursion?

Recursion is a programming technique where a method calls itself to find result.
     You need to follow these steps to work with Recursion successfully,
  • You need to figure out a stopping point which can be resolve without calling recursive function.
  • With calling every recursive method, you must reduce or approach to the stopping point otherwise you will get java.lang.StackOverFlowError(Learn more about StackOverFlowError)
Let’s consider the following recursive code:

Grab The Button...

Grab the above button and add to your blog or website to get easy access to Virtual Species. Simply click the textbox, copy the code and paste where you want to see the button. That's it!