+ 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...
12 Réponses
+ 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
+ 7
Ipang
https://code.sololearn.com/chWaAsN47xJ8/?ref=app
Unfortunately, not working...
+ 4
Actually, the technique I am using works only for 1 specific input...
I need a general logic...
+ 4
I need some time since I have to copy it from my PC
+ 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.
+ 2
Show us your attempt.
+ 2
Post it here, so we can see how can we improve it.
+ 2
I have it in C, will post it when your code is shared here Shadow Ninja
+ 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
+ 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.
0
Thnax
- 2
<redacted>
Techtok7 Please do not spam advertise your instagram page. Thank you.