Skip to content

Instantly share code, notes, and snippets.

@vanjikumaran
Created September 17, 2015 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vanjikumaran/0ca848fd7f0448501bc3 to your computer and use it in GitHub Desktop.
Save vanjikumaran/0ca848fd7f0448501bc3 to your computer and use it in GitHub Desktop.
import java.lang.Math;
public class NxNPattern
{
public static void main(String[] args)
{
for (int i = 0, j = 0; i < 49; i++) {
if (i % 7 == 0) {
if (j > 0) System.out.println();
j++;
}
int x = Math.abs(i % 7 - 3);
int y = Math.abs(j - 4);
if (x < y) System.out.print(y + 1);
else System.out.print(x + 1);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment