Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8834381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:59:56+00:00 2026-06-14T08:59:56+00:00

I’m having a problem printing columns. When the code reaches 100 it stops reading

  • 0

I’m having a problem printing columns. When the code reaches “100” it stops reading what is below it because it’s empty:

public class Column{

  public static void main( String[] arg )
  {

    int[][] uneven = 
        { { 1, 3, 100, 6, 7, 8, 9, 10},
          { 0, 2},
          { 0, 2, 4, 5},
          { 0, 2, 4, 6, 7},
          { 0, 1, 4, 5 },
          { 0, 1, 2, 3, 4, 5, 6 }};

    for ( int col=0; col < uneven.length; col++ )
    {
      System.out.print("Col " + col + ": ");
      for( int row=0; row < uneven.length; row++ ) 
        System.out.print( uneven[row][col] + " ");
      System.out.println();
    }
  }
}

What should I do so that it will continue reading the column?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T08:59:57+00:00Added an answer on June 14, 2026 at 8:59 am

    To print a variable length 2-D array, your inner loop runs from 0 to the current row length : –

    for (int i = 0; i < arr.length; i++) {
    
        for (int j = 0; j < arr[i].length; j++) {  // Closely see inner loop
    
            System.out.println(arr[i][j]);
        }
    }
    

    arr[i] is the current row. And arr[i].length gives the number of columns in that row.

    You can infer it like this: –

    • arr is a 2-D array.
    • So, each element of your arr is a 1-D array.
    • So, arr[i] is a 1-D array. Which represents each row.
    • To get number of columns in each row, you do arr[i].length

    Now, you can apply the same thing in your problem.


    Actually, your for loop is running wrongly. Your outer loop is running from col = 0 to col < uneven.length, but it should run from: – row = 0 to row < uneven.length

    So, your for loop should be like: –

    for ( int row=0; row < uneven.length; row++ )
    {
       System.out.print("Row " + row + ": ");
    
       for( int col=0; col < uneven[row].length; col++ ) { 
         System.out.print( uneven[row][col] + " ");
       }
       System.out.println();
    }
    

    UPDATED : –

    Ok, I got your question wrong first. If you want to print column wise, you can use this code: –

    int[][] uneven = 
        { { 1, 3, 100, 6, 7, 8, 9, 10},
          { 0, 2},
          { 0, 2, 4, 5},
          { 0, 2, 4, 6, 7},
          { 0, 1, 4, 5 },
          { 0, 1, 2, 3, 4, 5, 6 }};
    
        int max = -1;
        for ( int row = 0; row < uneven.length; row++ ) {
            if (uneven[row].length > max) {
                max = uneven[row].length;
            }
        }
        System.out.println(max);
        for (int i = 0; i < max; i++) {
            for (int j = 0; j < uneven.length; j++) {
                if (uneven[j].length <= i) {
                    continue;
                }
                System.out.print(uneven[j][i] + " ");
            }
            System.out.println();
        }
    

    First you need to find the max among all number of columns in each row.

    Then run the loop again, from 0 to max columns. Now, since you have a lop for columns, now you need another one for rows. And that will be your inner loop.

    Now, in inner loop, you cannot just print the array element at the (j, i) index, because the current row might not have max number of columns. So, you need to put an if-condition to check that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I've tracked down a weird MySQL problem to the two different ways I was

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.