Input/Output for pairs of numbers: Difference between revisions

Content deleted Content added
m →‎{{header|Unix Shell}}: Changed language name
J entry
Line 128:
sums = map sum nums
mapM_ print sums</lang>
 
=={{header|J}}==
<lang J>
$ cat <<EOF | jconsole -js '([: exit 0: [: smoutput [: ,. [: ({. {. }.) [: (+/"1) [: (0&".;._2) (1!:1)) 3'
> 5
> 1 2
> 10 20
> -3 5
> 100 2
> 5 5
> EOF
3
30
2
102
10
</lang>
Considerably simpler than [[http://rosettacode.org/wiki/Input/Output_for_Lines_of_Text#J|see explanation]] output for lines of text, this sentence is a single fork. Unless the fill is customized, J pads numeric arrays with 0. We form the +/"1 (row sums), then use the sum of the first row of the beheaded sums ({. {. }.) for display. ,. (raveled items) reshapes the vector into a column-vector shaped matrix. And the [: (cap) causes the monadic form of the verb to cap's right.
 
=={{header|Java}}==