ReggedArray in Java Program

ReggedArray is one part of 2-D array.

In this array first we have to just set row of 2-D array.

int x[][] = new int[3][]; // set only row first

After that we have to individual set each row columns.

x[0] = new int[1];   // set 1 column in 1st row

x[1] = new int[2];   // set 2 column in 2nd row

x[2] = new int[3];   // set 3 column in 3rd row

 

10
2030
405060

 

 

Let’s see how to work in program : ReggedArray

 

class reggedArray1

{

public static void main(String args[])

{

int x[][] = new int[3][];

x[0] = new int[1];

x[1] = new int[2];

x[2] = new int[3];

x[0][0] = 10;

x[1][0] = 20;

x[1][1] = 30;

x[2][0] = 40;

x[2][1] = 50;

x[2][2] = 60;

for(int i=0;i<=2;i++)

{

for(int j=0;j<=i;j++)

{

System.out.print(x[i][j] + ” “);

}

System.out.println();

}

}

}

Output:

10

20 30

40 50 60

 

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS

758total visits,1visits today


mayank

Hello, I am Maddy a Java blogger, trainer and developer

Related articles

5 Comments

  1. September 29, 2016 - 12:41 pm

    A lot of thanks for your own effort on this blog. My aunt take interest in making time for internet research and it’s easy to see why. Most of us hear all about the dynamic mode you give practical secrets by means of the web site and as well as foster participation from others about this idea so my daughter is without a doubt starting to learn a lot. Enjoy the rest of the year. You are always doing a great job.

  2. September 30, 2016 - 5:01 am

    I抦 impressed, I have to say. Actually not often do I encounter a blog that抯 each educative and entertaining, and let me let you know, you may have hit the nail on the head. Your idea is outstanding; the issue is one thing that not enough persons are talking intelligently about. I’m very pleased that I stumbled throughout this in my seek for something regarding this.

  3. September 30, 2016 - 9:57 pm

    I must get across my gratitude for your kind-heartedness supporting those people who have the need for help with the subject. Your real commitment to getting the solution around was rather effective and has specifically permitted many people much like me to attain their aims. The warm and friendly help can mean a whole lot to me and further more to my mates. Thanks a lot; from each one of us.

  4. October 1, 2016 - 1:31 am

    I抦 impressed, I need to say. Actually not often do I encounter a weblog that抯 both educative and entertaining, and let me tell you, you have got hit the nail on the head. Your idea is excellent; the difficulty is something that not sufficient persons are talking intelligently about. I’m very blissful that I stumbled across this in my search for one thing regarding this.

  5. October 2, 2016 - 2:25 am

    Your home is valueble for me. Thanks!?

Leave a Reply

Your email address will not be published. Required fields are marked *

Your comments (*)

Name (*)

Your full name please.

Email address (*)

Used for gravatar.

Website

Link back if you want.

Enter Captcha Here :*

Reload Image

EmailEmail
PrintPrint