473,385 Members | 1,872 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,385 software developers and data experts.

Array that has this kind of graphical illustration

I basically need help getting this kind of illustration using Arrays:

ex:


3
5 6
9 0 2
3 4 1 4
3 1 2 3 4

the variables are just examples, I just need to know how can I do that without having it like this:

3 0 0 0 0
5 6 0 0 0
9 0 2 0 0
3 4 1 4 0
3 1 2 3 4

Thank You!!
Mar 16 '10 #1

✓ answered by jkmyoung

Let's say you have an array of arrays,
Expand|Select|Wrap|Line Numbers
  1. int[][]array = new int[5][];
  2. int i,j;
  3.  
  4. You initialize the arrays like so:
  5. for (i = 0; i < 5; i++){
  6.     array[i] = new int[i+1];
  7. }
Then you set the values of the array somewhere. eg, array[0][0] = some value, array [1][0] = another value, etc... When you want to print it, use a nested for loop like so, which gets the length of each of the arrays:
Expand|Select|Wrap|Line Numbers
  1. for (i = 0; i < 5; i++){
  2.     int[] temp = array[i];
  3.     int len = temp.length;
  4.     for (j = 0; j < len; j++){
  5.         System.out.print(temp[j]+"\t");
  6.     }
  7.     System.out.println();
  8. }
Don't know if you wanted arrays or a vector or something else. Eg, maybe you want to store all the number in the same array

6 1481
jkmyoung
2,057 Expert 2GB
Can we see how you're storing your arrays? eg are you actually creating an array of length 5, and storing the zeroes?

If you only create an array of the size you want to output, it might make it easier; just use the .length property when outputting it.
Mar 16 '10 #2
The zeros are just an example of the arrays.

I just want to have the output like this:
3
5 6
9 0 2
3 4 1 4
3 1 2 3 4

can you teach me how can I get it without affecting the shape?

thanks!
Mar 16 '10 #3
jkmyoung
2,057 Expert 2GB
Let's say you have an array of arrays,
Expand|Select|Wrap|Line Numbers
  1. int[][]array = new int[5][];
  2. int i,j;
  3.  
  4. You initialize the arrays like so:
  5. for (i = 0; i < 5; i++){
  6.     array[i] = new int[i+1];
  7. }
Then you set the values of the array somewhere. eg, array[0][0] = some value, array [1][0] = another value, etc... When you want to print it, use a nested for loop like so, which gets the length of each of the arrays:
Expand|Select|Wrap|Line Numbers
  1. for (i = 0; i < 5; i++){
  2.     int[] temp = array[i];
  3.     int len = temp.length;
  4.     for (j = 0; j < len; j++){
  5.         System.out.print(temp[j]+"\t");
  6.     }
  7.     System.out.println();
  8. }
Don't know if you wanted arrays or a vector or something else. Eg, maybe you want to store all the number in the same array
Mar 16 '10 #4
Thank you!

How can I change the values because when i output its all zeros:

0
0 0
0 0 0
0 0 0 0
0 0 0 0 0


thanks again!
Mar 16 '10 #5
jkmyoung
2,057 Expert 2GB
Then you set the values of the array somewhere.
eg,
array[0][0] = 3;
array [1][0] = 5;
etc...
Mar 16 '10 #6
thank you very much!
Mar 17 '10 #7

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

Similar topics

9
by: mark | last post by:
I have an array as follows $sounds = array(); $sounds = "fishes/1/sound.php"; $sounds = "fishes/2/sound.php"; $sounds = "fishes/3/sound.php"; $sounds = "fishes/4/sound.php"; $sounds =...
6
by: Vamsee | last post by:
I have a 4D array: float T; ( have to go atleast upto T if system supports) How to malloc() it? can you please give me a brief illustration because I haven't found any article dealing with...
8
by: ehames | last post by:
Hi guys, As far as I know, for any type T, and positive integer N, if I have an array declared as: T array; then, &array and array are the same element. Is there any reason why a
4
by: Janus Knudsen | last post by:
Hello Im getting an error when I try to convert like this: string arrDSN; objDSN.GetDataSourceList(arrDSN) And the error: Argument '1': cannot convert from 'string' to 'ref System.Array'
2
by: David | last post by:
Hello. I need to create JPG file base on data from some array of bytes without using any graphical functions. So I need the function which will get array of bytes as parameter and write it byte...
24
by: RyanTaylor | last post by:
I have a final coming up later this week in my beginning Java class and my prof has decided to give us possible Javascript code we may have to write. Problem is, we didn't really cover JS and what...
7
by: Sam Kong | last post by:
Hello! My question would not be very practical but just out of curiosity. In JavaScript, Array is a subclass of Object. Well maybe not exactly... but sort of... For normal objects, you can...
7
by: repekto.argosoft | last post by:
Hi, I'm working with Marshalling. I got an idea to pass an object to the Native side as a byte array i.e. as void* in terms of C. For example: I have a .NET structure Point that contains...
9
by: devloop | last post by:
Hi, I am a JAVA developer who just started with php5 (on a WAMPP with php5.2.1). I´ve the following problem with a little class (I wanted to put objects into the array later but even with...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

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.