473,387 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Creating an array (matrix) that is using user inputs

Alright, so I just start self-learning for computer science over Internet, and there is a question that I don't know how to do it. Please help by giving me a hint or something.

Question:
Create an array (matrix) by asking the users for a number of rows and columns. Then ask the users to input each value for the matrix. Keep all the numbers as Integer.

Solve:
So I start by asking the users a number of rows and columns (let's say 4x4), but then I don't know how to ask user to input each value for the matrix. Thank you
Feb 17 '16 #1
1 1376
chaarmann
785 Expert 512MB
You just use a double for-loop. The inner iterates over the columns, the outer over the rows.
Inside your double loop, you read the user input in a variable, the same way you do it when you ask for number of rows.
Then you copy the variable into the array:
Expand|Select|Wrap|Line Numbers
  1. int rowCount = ... // read number of rows from user
  2. int columnCount = ... // read number of columns from user
  3. int[][] array = new int[rowCount][columnCount];
  4. for(int row = 0; ...)
  5. {
  6.    for(int column = 0; ...)
  7.    {
  8.     ... // tell user which row/column to input
  9.     int userInput = ... // read in value from user
  10.     array[row][column] = userInput;
  11.    }
  12. }
Feb 17 '16 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Sven Neuberg | last post by:
Hi, I have been handed the task of updating and maintaining a web application, written in ASP and Javascript, that takes complex user inputs in HTML form and submits them to server-side ASP...
10
by: jeff regoord | last post by:
A user inputs a float value. The scanf() function gets the value. However, I need to create an error handler with an if else statement saying invalid input if the input is not a number. Does...
1
by: Scott | last post by:
Hi, I'm using a form to collect values for later analysis. My question is, how do I validate the value the user inputs into a textbox? For example, many of the values require a real number and...
6
by: Jerry Spence1 | last post by:
Why doesn't the following work in my ASP program? I have imported ADOX I am trying to create a temporary database on the user's PC. The example is taken from Microsoft. Dim cat As Catalog =...
6
by: jrshack | last post by:
I have a web form that users input answers and when submitted I want the ASP code to place the user inputs into certain locations of a HTML form. The form is then automatically opened in a new...
1
by: csgirlie | last post by:
I'm trying to store or arrange three sets of two-dimensional data into three 2xN matrices that are stored as NumPy arrays. import os # for file handling functions import numpy as...
3
by: raras | last post by:
could somebody help me to write the script of program to multiply 2D matrix using function and pointer? please ... thanx for helping me!
3
by: akristof | last post by:
OK so pretty close to a beginner here so sorry if this sounds really basic or dumb. I'm trying to create a simple "poll" which allows users to add options to the poll in addition to voting on the...
0
by: onlygoodnoiz | last post by:
Hello everyone I am struggling on this country capital problem where the user inputs a country and the country and capital are suppose to be the output. Also even if the user enters Sp for spain, all...
3
Ajay Bhalala
by: Ajay Bhalala | last post by:
Hello all, I want to make a script for multiplication of 2 matrix using 2D array in php. Can anyone provide the code or program for it. or can anyone give the hint about this? Please help...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.