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 8993689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:14:52+00:00 2026-06-15T23:14:52+00:00

So here’s my problem. I have to write a program that will fill array

  • 0

So here’s my problem. I have to write a program that will fill array with random numbers(and it’s ok), then it’s necessary to print only even index numbers or only odd value numbers(j). Tried like this but when i put if statement and it shows every even number (index and value-the second in array) so it wrong. What should i do so?

import java.util.Random;

public class Array {

public static void main(String[] args)
{
    int rows = 5;
    int colu = 2;
    
    Random r = new Random();
    
    int [][] array = new int [rows][colu];
    
    for(int row = 0; row < array.length; row++)
    {
        for(int col = 0; col < array[row].length; col++)
        {
            array[row][col] = r.nextInt(10);
        }
    }
    
    for(int i = 0; i < array.length; i++)
    {       
        for(int j = 0; j < array[i].length; j++)
        {
            if(array[i][j]%2 == 0){
            System.out.print(array[i][j] + " ");
            }

            }
        }
        System.out.println();
    }
}

How it should like

Thanks

  • 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-15T23:14:53+00:00Added an answer on June 15, 2026 at 11:14 pm

    I’m going to take a stab at this but I’m not sure if I quite understand yet.

    int array[][] = new int[row][col];
    // ... populate the array with random numbers, works fine...
    
    // Let's traverse the first column.
    for (int i = 0; i < row; i++) {
        int value = array[i][0]; // col 0 means first column
        if (value % 2 == 0) {
            // ...
        }
    }
    
    // Let's traverse the second column.
    for (int i = 0; i < row; i++) {
        int value = array[i][1]; // col 1 means second column
        // ...
    }
    

    Is this what you mean? If it is, do you see the pattern and how you could generalize this and make the code a bit smaller?

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

Sidebar

Related Questions

Here's the code I have. It works. The only problem is that the first
Here's the problem....I have three components...A Page that contains a User Control and a
Here is an example: I write html code inside of textarea, then I swap
Here's what I'm trying to accomplish with this program: a recursive method that checks
Here's my problem I have this javascript if (exchRate != ) { function roundthecon()
Here's the setup - I have a view that lists products. On that same
Here is a scenario: User installs .NET application that you have made. After some
Here is my problem : I have a post controller with the action create.
Here is the problem I'm trying to solve for my game. I have this
Here is my problem. Our tech. writer or customer service will often create new

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.