Creating an Array: Difference between revisions
Content added Content deleted
(→{{header|JavaScript}}: array initialization gotcha) |
(added J solution) |
||
Line 244: | Line 244: | ||
print,a^2 |
print,a^2 |
||
9 25 64 49 |
9 25 64 49 |
||
=={{header|J}}== |
|||
"Creating an array" is topic seldom discussed in J as <i>every</i> verb takes array argument(s) |
|||
and return array results. (That is, <i>everything</i> creates an array.) |
|||
a=: 3 4 $ 3 1 4 1 5 9 2 6 5 3 5 8 NB. make a 3-by-4 table |
|||
a NB. display a |
|||
3 1 4 1 |
|||
5 9 2 6 |
|||
5 3 5 8 |
|||
b=: 10 20 30 NB. make a 3-element list |
|||
a + b NB. add corresponding items of a and b |
|||
13 11 14 11 |
|||
25 29 22 26 |
|||
35 33 35 38 |
|||
] c=: 3 4 $ 'eleemosynary' NB. make a 3-by-4 character table and display it |
|||
elee |
|||
mosy |
|||
nary |
|||
|."1 c NB. reverse each item of c |
|||
eele |
|||
ysom |
|||
yran |
|||
=={{header|Java}}== |
=={{header|Java}}== |