See this logicimport java.io.*;class spiral{int check(int r){ String str=Integer.toString(r);if(str.length()==1){return 1;}else{ return 0;}}void main()throws IOException{int t=1,r=0,e=-1,i,j,n;InputStreamReader read=new InputStreamReader(System.in);BufferedReader in=new BufferedReader(read);System.out.println("enter n then the dda");n=Integer.parseInt(in.readLine());int a[][]=new int[n][n];int l=n;String pnt;while(n>0){for(i=1;i<=n;i++){ a[r][++e]=t++;}for(i=1;i<=n-1;i++){a[++r][e]=t++;}for(i=1;i<=n-1;i++){a[r][--e]=t++;}for(i=1;i<=n-2;i++){a[--r][e]=t++;}n=n-2; }for(i=0;i<l;i++){for(j=0;j<l;j++){ if(check(a[i][j])==1){ pnt="0";}else {pnt="";}System.out.print(pnt+a[i][j]+" ");}System.out.println();}}}
nice logic
sir can u plz post the answers to the boolean,karnaugh and those questions in ur site
Post a Comment
3 comments:
See this logic
import java.io.*;
class spiral
{
int check(int r)
{ String str=Integer.toString(r);
if(str.length()==1)
{return 1;}
else{ return 0;}
}
void main()throws IOException
{
int t=1,r=0,e=-1,i,j,n;
InputStreamReader read=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(read);
System.out.println("enter n then the dda");
n=Integer.parseInt(in.readLine());
int a[][]=new int[n][n];
int l=n;String pnt;
while(n>0)
{
for(i=1;i<=n;i++)
{
a[r][++e]=t++;
}
for(i=1;i<=n-1;i++)
{
a[++r][e]=t++;
}
for(i=1;i<=n-1;i++)
{
a[r][--e]=t++;
}
for(i=1;i<=n-2;i++)
{
a[--r][e]=t++;
}
n=n-2;
}
for(i=0;i<l;i++)
{
for(j=0;j<l;j++)
{ if(check(a[i][j])==1)
{ pnt="0";}
else {pnt="";}
System.out.print(pnt+a[i][j]+" ");
}
System.out.println();
}
}
}
nice logic
sir can u plz post the answers to the boolean,karnaugh and those questions in ur site
Post a Comment