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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:45:53+00:00 2026-06-18T12:45:53+00:00

I have declared an array that i would like to multiply the value of

  • 0

I have declared an array that i would like to multiply the value of the first column by value of the second column of each row and create a grand sum of these products. I have tried the code listing below, what am i missing

public class Arrays {
    public static void(String[] args) {

        int array_x[][]={{9,8},{2,17},{49,4},{13,119},{2,19},{11,47},{3,73}};
        int sum = 0;

        for (int i = 0; i < array_x.length; i++) {
            for (int j = 0; j < array_x.length; j++) {
                array_x[i][j] = i * j;
                System.out.println("\n" + array_x[i][j])
            }
        }

    }
}

The output should be something like
9*8=72
2*17=34 etc then sum the whole results as 72+34+….

  • 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-18T12:45:54+00:00Added an answer on June 18, 2026 at 12:45 pm

    The code you wrote had several issues, including the fact that it would not compile because you had a different number of open and closed brackets, you didn’t specify the function name (which I assumed to be main) and there was a ; missing. However the biggest issue was a logical one: you only need a single for to do what you want to do. You know that the indices of the second dimension of the array are going to be 0 and 1, because as you said the array has only two columns. Also, you need to accumulate the products into sum, instead you initialized sum to 0 and never updated it. Finally, the instruction array_x[i][j] = i * j multiplies the indices instead of the values, so the result is not what you expect, and this result is put into array_x, which is the wrong place because you really don’t need to alter the input array.

    class Arrays{
    
        public static void main(String[] args){
    
            int array_x[][]={{9,8},{2,17},{49,4},{13,119},{2,19},{11,47},{3,73}};
    
            int sum=0;
    
            for(int i=0;i<array_x.length;i++) {
                int prod = array_x[i][0] * array_x[i][1];
                System.out.println("\n"+prod);
                sum += prod;
            }
    
            System.out.println("Final: " + sum);
        }
    }
    

    The code you originally wrote is actually what you need to build a multiplication table, but in that case you need an array with an equal number of rows and columns.

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

Sidebar

Related Questions

I would like to have an array of treenode in such a way that
I have a variable length array of strings declared in javascript that contains Dungeons
I have a variable declared like this in a class: Entity *array[BOARD_SIZE][BOARD_SIZE]; I need
I have declared a column of type NVARCHAR(MAX) in SQL Server 2008, what would
So basically I would like to create a function that when alerted, returns the
Say I have an array of Strings declared like this: String[] strings = new
I have an array declared in my header file like this: int snapshot[kSnapshotSize]; which
I have an array of structs, each of which describes what I would call
I have a project that requires the following. Four arrays will be declared in
I have declared an array in the form: var refs = { 'EE810': Presence

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.