QUESTION You’re given an even number n. If n=4, you have to print the following pattern : 4444 4334 4334 4444 If n=6, then the pattern should be like this : 666666 655556 654456 654456 655556 666666
// JAVA CODE
import java.util.*;
import java.lang.*;
import java.io.*;
class zohoquestion{
public static void main(String args[]) {
Scanner sc= new Scanner(System.in);
int n=sc.nextInt();int limit=0;
int s=n;
int a[][]= new int[n][n];
int l=0;int r=n-1;
while(limit<n){
for(int i=l;i<=r;i++){
for(int j=l;j<=r;j++)
if(i==l || i==r || j==l || j==r)
a[i][j]=n;
}
l++;r--;n--;limit++;
}
for(int i=0;i<s;i++){
for(int j=0;j<s;j++)
System.out.print(a[i][j]);
System.out.println();
}
}
}
import java.util.*;
import java.lang.*;
import java.io.*;
class zohoquestion{
public static void main(String args[]) {
Scanner sc= new Scanner(System.in);
int n=sc.nextInt();int limit=0;
int s=n;
int a[][]= new int[n][n];
int l=0;int r=n-1;
while(limit<n){
for(int i=l;i<=r;i++){
for(int j=l;j<=r;j++)
if(i==l || i==r || j==l || j==r)
a[i][j]=n;
}
l++;r--;n--;limit++;
}
for(int i=0;i<s;i++){
for(int j=0;j<s;j++)
System.out.print(a[i][j]);
System.out.println();
}
}
}
Before coping and posting anything on your blog first check weather it is working or not.
ReplyDeletesry fr the inconvenience... There was actually no error in logic... The mistake was we didn't include class name and library files(we have changed now)... We won't make this in future... Thanks for bringing it to our notice😊
DeleteMr Velmurugan, you are doing an extraordinary job. Please keep up the good work and educate us more! God bless.
ReplyDeleteHi... Thanks for motivating us with such kind words :)
Delete