Get the matrix of Levensthein Distance - java

I write some code of java that implemented Levensthein distance to calculate the similarity from two string. My code is like this :
public class LevenshteinDistance {
public LevenshteinDistance() {
}
public double similarity(String s1, String s2) {
if (s1.length() < s2.length()) { // s1 should always be bigger
String swap = s1;
s1 = s2;
s2 = swap;
}
int bigLen = s1.length();
if (bigLen == 0) {
return 1.0; /* both strings are zero length */ }
return (bigLen - computeEditDistance(s1, s2)) / (double) bigLen;
}
public int computeEditDistance(String s1, String s2) {
s1 = s1.toLowerCase();
s2 = s2.toLowerCase();
int[] costs = new int[s2.length() + 1];
for (int i = 0; i <= s1.length(); i++) {
int lastValue = i;
for (int j = 0; j <= s2.length(); j++) {
if (i == 0) {
costs[j] = j;
} else {
if (j > 0) {
int newValue = costs[j - 1];
if (s1.charAt(i - 1) != s2.charAt(j - 1)) {
newValue = Math.min(Math.min(newValue, lastValue), costs[j]) + 1;
}
costs[j - 1] = lastValue;
lastValue = newValue;
}
}
}
if (i > 0) {
costs[s2.length()] = lastValue;
}
}
return costs[s2.length()];
}
public double printDistance(String s1, String s2) {
System.out.println("[Edit Distance] : " + s1 + " and " + s2 + " have similarity is = " + similarity(s1, s2) * 100 + " %");
return similarity(s1, s2) * 100;
}
public static void main(String[] args) {
LevenshteinDistance lv = new LevenshteinDistance();
lv.printDistance("164164617044", "164164617044");
}
}
From my code above, I have an output like this :
[Edit Distance] : 164164617044 and 164164617044 have similarity is = 100.0 %
How to get the output the matriks that represented Levensthein distance like
1 6 4 1 6 4 6 1 7 0 4 4
0 1 2 3 4 5 6 7 8 9 10 11 12
1 1 0 1 2 3 4 5 6 7 8 9 10 11
6 2 1 0 1 2 3 4 5 6 7 8 9 10
4 3 2 1 0 1 2 3 4 5 6 7 8 9
1 4 3 2 1 0 1 2 3 4 5 6 7 8
6 5 4 3 2 1 0 1 2 3 4 5 6 7
4 6 5 4 3 2 1 0 1 2 3 4 5 6
6 7 6 5 4 3 2 1 0 1 2 3 4 5
1 8 7 6 5 4 3 2 1 0 1 2 3 4
7 9 8 7 6 5 4 3 2 1 0 1 2 3
0 10 9 8 7 6 5 4 3 2 1 0 1 2
4 11 10 9 8 7 6 5 4 3 2 1 0 1
4 12 11 10 9 8 7 6 5 4 3 2 1 0
for the help, thanks

The thing is that your implementation only calculates the distance and not the resulting matrix.
This solution is based on the Wagner–Fischer algorithm:
public class LevenshteinDistance {
public static void main(String[] args) {
String str1 = "164164617044", str2 = "164164617044";
System.out.print("String 1: \"" + str1 + "\" String 2: \"" + str2
+ "\".\n\n");
int[][] resultingMatrix = resultingMatrix(str1, str2);
int distance = resultingMatrix[str1.length()][str2.length()];
double similarity = similarity(str1, str2, distance), similarityPercentage = similarity * 100.0;
System.out.print("Levenshtein distance = " + distance + ".\n\n");
System.out.print("Similarity = " + similarity + ".\n\n");
System.out.print("Similarity Percentage = " + similarityPercentage
+ "%.\n\n");
System.out.print("Resulting Matrix:\n");
for (int charsInStr2 = 0; charsInStr2 < str2.length(); charsInStr2++) {
if (charsInStr2 == 0) {
System.out.print(String.format("%-5s%-5s%-5s", " ", " ", "'" + str2.charAt(charsInStr2) + "'"));
} else {
System.out
.print(String.format("%-5s", "'" + str2.charAt(charsInStr2)+ "'"));
}
}
System.out.print("\n");
for (int i = 0; i < resultingMatrix.length; i++) {
String line = "";
for (int j = 0; j < resultingMatrix[i].length; j++) {
line += String.format("%-5s", resultingMatrix[i][j]);
}
if(i == 0)
System.out.printf("%-4s %s\n", " ", line);
else{
System.out.printf("%-4s %s\n", "'" + str1.charAt(i-1) + "'", line);
}
}
}
public static int[][] resultingMatrix(String str1, String str2) {
int[][] dist = new int[str1.length() + 1][str2.length() + 1];
for (int i = 0; i <= str1.length(); i++) {
dist[i][0] = i;
}
for (int j = 1; j <= str2.length(); j++) {
dist[0][j] = j;
}
for (int i = 1; i <= str1.length(); i++)
for (int j = 1; j <= str2.length(); j++)
dist[i][j] = Math
.min(Math.min(dist[i - 1][j] + 1, dist[i][j - 1] + 1),
dist[i - 1][j - 1]
+ ((str1.charAt(i - 1) == str2
.charAt(j - 1)) ? 0 : 1));
return dist;
}
public static double similarity(String str1, String str2, int distance) {
double bigLenght = Math.max(str1.length(), str2.length());
return (bigLenght - distance) / bigLenght;
}
}
Example:
String 1: "164164617044" String 2: "164164617044".
Levenshtein distance = 0.
Similarity = 1.0.
Similarity Percentage = 100.0%.
Resulting Matrix:
'1' '6' '4' '1' '6' '4' '6' '1' '7' '0' '4' '4'
0 1 2 3 4 5 6 7 8 9 10 11 12
'1' 1 0 1 2 3 4 5 6 7 8 9 10 11
'6' 2 1 0 1 2 3 4 5 6 7 8 9 10
'4' 3 2 1 0 1 2 3 4 5 6 7 8 9
'1' 4 3 2 1 0 1 2 3 4 5 6 7 8
'6' 5 4 3 2 1 0 1 2 3 4 5 6 7
'4' 6 5 4 3 2 1 0 1 2 3 4 5 6
'6' 7 6 5 4 3 2 1 0 1 2 3 4 5
'1' 8 7 6 5 4 3 2 1 0 1 2 3 4
'7' 9 8 7 6 5 4 3 2 1 0 1 2 3
'0' 10 9 8 7 6 5 4 3 2 1 0 1 2
'4' 11 10 9 8 7 6 5 4 3 2 1 0 1
'4' 12 11 10 9 8 7 6 5 4 3 2 1 0
Note that the Levensthein distance is always the element in the right bottom corner of the resulting matrix (resultingMatrix[str1Len][str2Len]). Also, take a look at the method for calculating the similarity in my solution.

Related

For loop to print a numeric pattern does not print the correct pattern

This is what it should look like
9 8 7 6 5 4 3 2 1 0
8 8 7 6 5 4 3 2 1 0
7 7 7 6 5 4 3 2 1 0
6 6 6 6 5 4 3 2 1 0
5 5 5 5 5 4 3 2 1 0
4 4 4 4 4 4 3 2 1 0
3 3 3 3 3 3 3 2 1 0
2 2 2 2 2 2 2 2 1 0
1 1 1 1 1 1 1 1 1 0
0 0 0 0 0 0 0 0 0 0
Here's my attempt.
public class Main {
public static void main(String[] args) {
int i = 9;
int count = -1;
while (i >= count) {
int j = i;
while (j > count) {
System.out.print(j + " ");
j--;
}
System.out.println();
count++;
}
}
}
Here's my actual output:
9 8 7 6 5 4 3 2 1 0
9 8 7 6 5 4 3 2 1
9 8 7 6 5 4 3 2
9 8 7 6 5 4 3
9 8 7 6 5 4
9 8 7 6 5
9 8 7 6
9 8 7
9 8
9
This obviously does not match the expected output. Can someone point out where the mistake is in the code?
This is a Solution that has the right output, but instead of using while-Loops I used for-Loops
public class Main {
public static void main(String[] args) {
int count1 = 9;
for (int i = count1; i >= 0; i--) {
int count2 = i;
if (count1 > count2) {
int tmp = count1 - count2;
for (int j = tmp; j > 0; j--) {
System.out.print(count2 + " ");
}
}
for (int j = count2; j >= 0; j--) {
System.out.print(j + " ");
}
System.out.println();
}
}
}
You can keep two outer variables, counter and multiplier, for the matrix size and repetitions' count respectively:
public class Main {
public static void main(String[] args) {
int counter = 15;
int multiplier = 1;
for (int i = counter; i >= 0; i--) {
for (int j = 0; j<multiplier; j++) {
System.out.printf("%3d", counter); //using %3d for spacing numbers nicely
}
for (int k = counter-1; k >= 0; k--) {
System.out.printf("%3d", k);
}
++multiplier;
--counter;
System.out.println();
}
}
}
For every horizontal line, where counter decreases, and multiplier increases (9 once on 1st line; 8 twice on the second line, etc.):
it will first print the counter, multiplier times;
it will then fill the rest of the line with counter-multiplier number of descending sequence integers, starting from counter-1;
at the end of outer loop's each iteration, a new line is printed.
Output would be:
9 8 7 6 5 4 3 2 1 0
8 8 7 6 5 4 3 2 1 0
7 7 7 6 5 4 3 2 1 0
6 6 6 6 5 4 3 2 1 0
5 5 5 5 5 4 3 2 1 0
4 4 4 4 4 4 3 2 1 0
3 3 3 3 3 3 3 2 1 0
2 2 2 2 2 2 2 2 1 0
1 1 1 1 1 1 1 1 1 0
0 0 0 0 0 0 0 0 0 0
Since you already have your answer, here are a couple alternatives.
String str = "9 8 7 6 5 6 3 2 1 0";
System.out.println(str);
for (int i = 9; i > 0; i--) {
str = str.replace(i+"",(i-1)+"");
System.out.println(str);
}
Or use the String.repeatmethod.
for (int i = 9; i >= 0; i--) {
System.out.print((i+" ").repeat(9-i));
for(int k = i; k >= 0; k--) {
System.out.print(k + " ");
}
System.out.println();
}
With the help of Java8 stream you can write the code as below:
public static void main(String[] args) {
IntStream.range(0, 10)
.forEach(i -> {
IntStream.range(0, 10).forEach(j -> {
System.out.print((9- (j < i ? i : j)) + " " );
});
System.out.println("");
});
}

TRIANGLE ALGORITHM [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
1
2 3
4 5 4
3 2 1 2
3 4 5 4 3
I want to make a triangle like that. I have tried making the triangle and the numbers but the numbers doesn't fit the triangle so the output isn't as expected. Please help.
Example input: n = 5;
1) This is the code to make the triangle.
int k = 1;
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
if (j <= i) {
System.out.print("* ");
} else {
System.out.print(" ");
}
}
System.out.println();
}
2) This is the code to make the numbers.
int k = 1;
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
if (i % 2 == 0) {
if (k == 5) {
break;
}
System.out.print(k + " ");
k++;
} else if (i % 2 != 0) {
if (k == 1) {
break;
}
System.out.print(k + " ");
k--;
}
}
}
We need to print a number of rows, with each row printed having the same number of values as the row number. If we were printing *'s, it would be easy:
static void printTriangle(int rowCount) {
for (int row = 1; row <= rowCount; row++) {
for (int i = 0; i < row; i++)
System.out.print("* ");
System.out.println();
}
}
printTriangle(5)
*
* *
* * *
* * * *
* * * * *
Instead of printing *'s, we want the values to come from a repeating sequence of 1 2 3 4 5 4 3 2 ....
The sequence is 8 long, so if we take an ever-increasing number a, starting at 0, and calculate remainder when dividing by 8, i.e. b = a % 8, we get a repeating sequence of 0 1 2 3 4 5 6 7 .... If we then calculate distance from 4, using c = Math.abs(4 - b), we get 4 3 2 1 0 1 2 3 .... If we subtract that from 5, i.e. d = 5 - c, we get 1 2 3 4 5 4 3 2 ..., i.e. the desired sequence.
static void printTriangle(int rowCount) {
int a = 0;
for (int row = 1; row <= rowCount; row++) {
for (int i = 0; i < row; i++) {
int b = a % 8;
int c = Math.abs(4 - b);
int d = 5 - c;
System.out.print(d + " ");
a++;
}
System.out.println();
}
}
The code can be reduced to:
static void printTriangle(int rowCount) {
for (int seq = 0, row = 1; row <= rowCount; row++) {
for (int i = 0; i < row; i++, seq++)
System.out.print((5 - Math.abs(4 - seq % 8)) + " ");
System.out.println();
}
}
printTriangle(10)
1
2 3
4 5 4
3 2 1 2
3 4 5 4 3
2 1 2 3 4 5
4 3 2 1 2 3 4
5 4 3 2 1 2 3 4
5 4 3 2 1 2 3 4 5
4 3 2 1 2 3 4 5 4 3
For the advanced version, we can make the max value printed be dynamic too:
static void printTriangle(int rowCount, int maxValue) {
String fmt = "%" + String.valueOf(maxValue).length() + "s ";
for (int row = 1, seq = 0; row <= rowCount; row++) {
for (int i = 0; i < row; i++, seq++)
System.out.printf(fmt, (maxValue - Math.abs(maxValue - 1 - seq % (maxValue * 2 - 2))));
System.out.println();
}
}
printTriangle(5, 5)
1
2 3
4 5 4
3 2 1 2
3 4 5 4 3
printTriangle(20, 14)
1
2 3
4 5 6
7 8 9 10
11 12 13 14 13
12 11 10 9 8 7
6 5 4 3 2 1 2
3 4 5 6 7 8 9 10
11 12 13 14 13 12 11 10 9
8 7 6 5 4 3 2 1 2 3
4 5 6 7 8 9 10 11 12 13 14
13 12 11 10 9 8 7 6 5 4 3 2
1 2 3 4 5 6 7 8 9 10 11 12 13
14 13 12 11 10 9 8 7 6 5 4 3 2 1
2 3 4 5 6 7 8 9 10 11 12 13 14 13 12
11 10 9 8 7 6 5 4 3 2 1 2 3 4 5 6
7 8 9 10 11 12 13 14 13 12 11 10 9 8 7 6 5
4 3 2 1 2 3 4 5 6 7 8 9 10 11 12 13 14 13
12 11 10 9 8 7 6 5 4 3 2 1 2 3 4 5 6 7 8
9 10 11 12 13 14 13 12 11 10 9 8 7 6 5 4 3 2 1 2

Need help getting the numbers to double all the way to the middle

I'm trying to create a pyramid that will double all the way to the center.
The code is producing this.
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
import java.util.Scanner;
for (i = 1; i<= lines; i++){ // sets rows (lines)
for (j = a; j >= 1; j--){ // dead space on left
System.out.printf(str," ");
}
for (k = 1; k != i; k++){ //left side numbers
String str1 = "" + k;
System.out.printf(str, str1);
}
a--;
for (int l = k; l >=1; l--){ // right side numbers
String str2 = "" + l;
System.out.printf(str, str2);
}
}
I expected it to look like this.
1
1 2 1
1 2 4 2 1
1 2 4 8 4 2 1
1 2 4 8 16 8 4 2 1
1 2 4 8 16 32 16 8 4 2 1
1 2 4 8 16 32 64 32 16 8 4 2 1
1 2 4 8 16 32 64 128 64 32 16 8 4 2 1
k and l should be used as exponents rather than as the numbers you are printing.
int lines = 8;
String str = "%4s"; //pads each number to 4 spaces
for (int i = 1; i <= lines; i++)
{
for (int j = 0; j < lines - i; j++) //Replaced a with lines - i
{
System.out.printf(str, " ");
}
for (int k = 1; k != i; k++)
{
//replaced k with 2 ^ (k - 1)
String str1 = "" + (int)(Math.pow(2, k - 1));
System.out.printf(str, str1);
}
for (int l = i; l >= 1; l--)
{
//replaced l with 2 ^ (l - 1)
String str2 = "" + (int)(Math.pow(2, l - 1));
System.out.printf(str, str2);
}
System.out.println(); //added newline between each line
}
Output:
1
1 2 1
1 2 4 2 1
1 2 4 8 4 2 1
1 2 4 8 16 8 4 2 1
1 2 4 8 16 32 16 8 4 2 1
1 2 4 8 16 32 64 32 16 8 4 2 1
1 2 4 8 16 32 64 128 64 32 16 8 4 2 1
Here is a solution that dynamically adjusts the spacing as needed.
The code uses <</>> bit-shifting to double/halve the numbers.
public static void printPyramidOfSquares(int lines) {
if (lines < 0 || lines > 63)
throw new IllegalArgumentException();
int width = Long.toString(1L << (lines - 1)).length();
for (int line = 1; line <= lines; line++) {
if (line < lines)
System.out.printf("%" + (lines - line) * (width + 1) + "s", "");
long val = 1;
for (int i = 1; i < line; i++, val <<= 1)
System.out.printf("%" + width + "d ", val);
for (int i = 1; i < line; i++, val >>= 1)
System.out.printf("%" + width + "d ", val);
System.out.printf("%" + width + "d%n", val);
}
}
Test
printPyramidOfSquares(4);
printPyramidOfSquares(5);
printPyramidOfSquares(8);
Output
1
1 2 1
1 2 4 2 1
1 2 4 8 4 2 1
1
1 2 1
1 2 4 2 1
1 2 4 8 4 2 1
1 2 4 8 16 8 4 2 1
1
1 2 1
1 2 4 2 1
1 2 4 8 4 2 1
1 2 4 8 16 8 4 2 1
1 2 4 8 16 32 16 8 4 2 1
1 2 4 8 16 32 64 32 16 8 4 2 1
1 2 4 8 16 32 64 128 64 32 16 8 4 2 1
Here is an alternative solution that calculates each row / col using the formula: "val = 2^(row - |lines - col - 1|)". It automatically adjusts the spacing using log base 10 to calculate the number of digits.
int s = 2 + (int) Math.log10(1 << lines);
IntStream.range(0, lines)
.mapToObj(r -> IntStream.range(0, 2 * lines - 1)
.map(c -> r - Math.abs(lines - c - 1))
.mapToObj(v -> v >= 0 ? String.format("%" + s + "d", 1 << v) : " ".repeat(s))
.collect(Collectors.joining()))
.forEach(System.out::println);

Trouble formatting with 2-dimensional array matrices

I need my matrices to look exactly like this.(with numbers lined up under text)
Here are the two matrices, and the result when added:
2 2 7 4 3 4 3 3 5 6 10 7
4 4 8 8 6 8 5 5 10 12 13 13
1 9 3 7 6 8 6 9 7 17 9 16
2 3 2 9 + 4 4 7 1 = 6 7 9 10
2 9 1 1 9 8 2 5 11 17 3 6
6 1 8 4 4 8 2 2 10 9 10 6
The results I am currently getting look like.
Here are the two matrices, and the result when added:
8 5 6 6 3 8 2 3 11 13 8 9
7 7 4 5 4 9 2 1 11 16 6 6
9 4 4 8 5 1 1 1 14 5 5 9
4 2 7 7 + 7 9 1 3 = 11 11 8 10
4 3 5 3 5 6 8 7 9 9 13 10
4 2 2 1 3 9 5 5 7 11 7 6
As you can see the code for the arrays sum is shifted to the right, and I am not quite sure how to fix this.
public static void printResult(int [][]array1, int [][]array2, int[][]sum, char arithmetic)
{
if (arithmetic == '+') {
// Text for two matrices when added
System.out.print("Here are the two matrices, and the result when added:\n");
// For loop to print array1 + array2 = sum with format
for (int i = 0; i < array1.length; i++) {
// For loop to print out array 1 and add string, if to place +
for (int j = 0; j < array1[i].length; j++) {
System.out.printf("%4s", array1[i][j]);
if (i == array1.length / 2 && j == array1[i].length-1) {
System.out.printf("%4s", '+');
}
}
System.out.print("\t");
// For loop to print out array2 and equals string, if to place =
for (int j = 0; j < array1[i].length; j++) {
System.out.printf("%2s", array2[i][j] + " ");
if (i == array1.length / 2 && j == array1[i].length-1) {
System.out.printf("%1s", '=');
}
}
System.out.print(" ");
// For loop to print out sum of array1 + array2
for (int j = 0; j < array1[i].length; j++) {
System.out.printf("%4s", sum[i][j]);
}
System.out.print("\n");
}
}
else if (arithmetic == '-') {
}
else if (arithmetic == '*') {
}
else if (arithmetic == '/') {
}
else if (arithmetic == '%') {
}
}
Also a 3x3 array when printed out looks like.
Here are the two matrices, and the result when added:
2 2 7 3 4 3 5 6 8
4 4 8 + 6 8 5 = 7 9 13
1 9 3 6 8 6 7 7
I think this is meant to insure that numbers, when printed, always take up 2 spaces:
System.out.printf("%2s", array2[i][j] + " ");
But because of the added (technically, concatenated) " ", you get a string that is bigger than the %2s field, so there is no padding of short numbers.
Plus, you have code to decide when to print the + & =, but each should be deciding between printing the symbol and printing a space, to keep everything lined up.

How to get the following formatted output?

I wrote the code to get the following formatted output, but when I enter number of rows in double digits, the output format changes. Why? How can I fix this?
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
Here is my code:
import java.util.*;
class PTri {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the no. of rows for which " +
"triangle has to be constructed");
int numrow = sc.nextInt();
for (int i = 1; i <= numrow; i++) {
for (int j = 1; j <= numrow - i; j++) {
System.out.print(" ");
}
for (int k = 1; k < i * 2; k++) {
System.out.print(Math.min(k, i * 2 - k) + " ");
}
System.out.println();
}
}
}
It's because the value in double digit will change the whole architecture.The set will shift to right one place. So you can put a condition like this. I have added one extra space between numbers to improve visibility.
import java.util.*;
class PTri {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the no. of rows for which " +
"triangle has to be constructed");
int numrow = sc.nextInt();
for (int i = 1; i <= numrow; i++) {
for (int j = 1; j <= (numrow - i); j++) {
System.out.print(" ");
}
for (int k = 1; k < i * 2; k++) {
int temp = Math.min(k, i * 2 - k);
if (temp > 9) {
System.out.print(temp + " ");
} else {
System.out.print(temp + " ");
}
}
System.out.println();
}
}
}
In this example I counted the digits, and for every digit I add an extra space.
The output of the value is formatted with leading zeros (digit-count).
public static void main(final String[] args) {
final Scanner sc = new Scanner(System.in);
System.out.println("Enter the no. of rows for which " +
"triangle has to be constructed");
final int numrow = 100;// sc.nextInt();
final int digits = (int) Math.log10(numrow) + 1;
for (int i = 1; i <= numrow; i++) {
for (int j = 1; j <= numrow - i; j++) {
System.out.print(" ");
for (int l = 0; l < digits; l++) {
System.out.print(" ");
}
}
for (int k = 1; k < i * 2; k++) {
final int value = Math.min(k, i * 2 - k);
System.out.print(String.format("%0" + digits + "d ", value));
}
System.out.println();
}
}
You can use String.format method:
"%2d" - format as a two-digit number.
"%02d" - format as a two-digit number with leading zeros.
Example:
// int n = 5;
int n = 12;
// number of digits
int digits = String.valueOf(n).length();
// format string
String format = "%" + digits + "d";
// output
System.out.println("n=" + n + ", format=" + format);
IntStream.rangeClosed(1, n)
.mapToObj(i -> IntStream.rangeClosed(-n, i)
.map(Math::abs)
.map(j -> j = i - j)
.filter(j -> j != 0)
.mapToObj(j -> j > 0 ?
String.format(format, j) : " " .repeat(digits))
.collect(Collectors.joining(" ")))
.forEach(System.out::println);
Output:
n=5, format=%1d
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
n=12, format=%2d
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 5 6 5 4 3 2 1
1 2 3 4 5 6 7 6 5 4 3 2 1
1 2 3 4 5 6 7 8 7 6 5 4 3 2 1
1 2 3 4 5 6 7 8 9 8 7 6 5 4 3 2 1
1 2 3 4 5 6 7 8 9 10 9 8 7 6 5 4 3 2 1
1 2 3 4 5 6 7 8 9 10 11 10 9 8 7 6 5 4 3 2 1
1 2 3 4 5 6 7 8 9 10 11 12 11 10 9 8 7 6 5 4 3 2 1
See also: Print the sum of the row and column in a 2d array after each row

Categories

Resources