[Solved]Please help me solve this ... | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

[Solved]Please help me solve this ...

If the user enters 3 Output 33333 32223 32123 32223 33333 If the user enters 4 4444444 4333334 4322234 4321234 4322234 4333334 4444444 This should work for any input...

12th Dec 2019, 10:10 AM
Shadow Ninja[#Inactive]
Shadow Ninja[#Inactive] - avatar
12 Answers
+ 2
This is my solution in Java. I hope it can help you. public class Program { public static void main(String[] args) { int n = 5; for (int i = 0; i < n + n - 1; i++ ){ for (int j = 0; j < n + n -1; j++){ System.out.print(Math.max(Math.abs(j-n+1)+1, Math.abs(i-n+1)+1)); } System.out.println(); } } } https://code.sololearn.com/cWvRLnaVLM0T/?ref=app
13th Dec 2019, 10:35 AM
Julio Codesal
Julio Codesal - avatar
13th Dec 2019, 7:25 AM
Shadow Ninja[#Inactive]
Shadow Ninja[#Inactive] - avatar
+ 4
Actually, the technique I am using works only for 1 specific input... I need a general logic...
12th Dec 2019, 10:34 AM
Shadow Ninja[#Inactive]
Shadow Ninja[#Inactive] - avatar
+ 4
I need some time since I have to copy it from my PC
12th Dec 2019, 10:38 AM
Shadow Ninja[#Inactive]
Shadow Ninja[#Inactive] - avatar
+ 4
n = 3 -> 5 * 5 n = 4 -> 7 * 7 matrix: (n * 2 - 1) x (n * 2 - 1) int limit = n * 2 - 1 Now you need to study each lines. 1. and last: print only n 2. and second last: print n, print limit-2 times n -1, print n ... At line n: print numbers from n to 1 to n (4321234) Hope this helps.
12th Dec 2019, 2:36 PM
Denise Roßberg
Denise Roßberg - avatar
+ 2
Show us your attempt.
12th Dec 2019, 10:33 AM
blACk sh4d0w
blACk sh4d0w - avatar
+ 2
Post it here, so we can see how can we improve it.
12th Dec 2019, 10:37 AM
blACk sh4d0w
blACk sh4d0w - avatar
+ 2
I have it in C, will post it when your code is shared here Shadow Ninja
12th Dec 2019, 4:25 PM
Ipang
+ 2
Shadow Ninja This is how I did it. I hope you can see through it and probably convert this into Java (if you wish). I limit the acceptable size from 1 - 9 because it doesn't look right with numbers having two or more digits : ) P.S. I saw this pattern in some C/C++ practice site before, but the solution on that site was different approach. Unfortunately I missed the site link, but maybe you can search for it, if you want to see the other approach. https://code.sololearn.com/cHuKqbWZkb0r/?ref=app
13th Dec 2019, 8:35 AM
Ipang
+ 2
Shadow Ninja * I don't think that you need to create an object * wrong method calling: Line 20 & 59 ob.process(A[][]); -> ob.process(A); * unknown variable Line 22 & 24 add int l, r, c inside main Edit: you don't need this loop: for(i=0;i<x;i++){ for(j=0;j<x;j++){ A[i][j]=0; } } When you create an int array, all values are 0.
13th Dec 2019, 2:24 PM
Denise Roßberg
Denise Roßberg - avatar
0
Thnax
25th Feb 2020, 1:58 PM
Sooraj m
Sooraj m - avatar
- 2
<redacted> Techtok7 Please do not spam advertise your instagram page. Thank you.
12th May 2020, 2:21 PM
Techtok7
Techtok7 - avatar