Elite Coders Society
Hello Guest!
Join us here in this forum!
Please Log in or Register to access more feature in this site.
Start Learning!

† Copyright © 2011 - EliteCoders.forums.ag †


Start sharing and learning new skills about programming and design by building connections with other professional and students.
 
HomeForumPortalCalendarGallerySearchRegisterLog in
Elite Coders Partner Links

EliteCoders™ News!
Hello Guest!, Welcome in our forum. Be active!

Share | 
 

 Magic Square Java

View previous topic View next topic Go down 
AuthorMessage
avatar
Admin[dElmARk]
Forum Owner
Forum Owner

Posts : 78
EC-Points : 6304
Thanked : 21
Join date : 15/10/2011
Age : 22
Location : Philippines

Hacker's Info
Hacking Exp:
0/0  (0/0)
Hacker Type: White Hat
Hacking Title:

PostSubject: Magic Square Java   Mon Nov 21, 2011 7:36 am

Code:
import java.util.*;
class magicSquare{
   public static void main(String[]args)   {
   Scanner del = new Scanner(System.in);
   System.out.print("Input Number: ");
   int N = del.nextInt();
   int square[][] = new int[N][N];
   System.out.println();
   square [0][(N -1) / 2] = 1;
   int key = 2, i = 0, j=(N-1)/2;
   while (key<=N *N)   {
   int k = i-1;
   if(k<0)
    k+= N;
    int l = j-1;
    if(l<0)
    l+= N;
    if(square[k][l]!=0)   
    i=(i+1)% N;
    else
    {
    i=k;
    j=l;
    }
    square[i][j] = key;
    key++;
    }
    for(i=0; i<N; i++){
    for(j = 0; j<N; j++)
      System.out.print(square [i][j] + "\t");
      System.out.println();
    }
   }
}

______________________________________
[You must be registered and logged in to see this image.]
[You must be registered and logged in to see this image.]
Back to top Go down
View user profile
avatar
Admin[Mr.Anon14]
Admin
Admin

Posts : 50
EC-Points : 1064
Thanked : 4
Join date : 08/11/2011
Age : 20
Location : Somewhere can't be seen

Hacker's Info
Hacking Exp:
0/0  (0/0)
Hacker Type: White Hat
Hacking Title:

PostSubject: Re: Magic Square Java   Mon Nov 21, 2011 4:58 pm

What is Magic Square?

______________________________________
[You must be registered and logged in to see this image.]
Facebook Page : [You must be registered and logged in to see this link.]
Blog : [You must be registered and logged in to see this link.]
My Facebook : [You must be registered and logged in to see this link.]
Thanks For All Your Support, I Appreciated It All
Want More Helps?
Wait For Some Useful Posts or Request It!

I am Grey Phantom , "The Hidden Phantom Of The Generations."

[You must be registered and logged in to see this image.]
[You must be registered and logged in to see this image.]
Back to top Go down
View user profile http://darkages.canadianforum.net
avatar
[FM]wapaklez
Head Moderator
Head Moderator

Posts : 26
EC-Points : 2065
Thanked : 6
Join date : 20/10/2011
Age : 25
Location : Philippines

PostSubject: Re: Magic Square Java   Mon Nov 21, 2011 5:29 pm

Magic square

In recreational mathematics, a magic square of order n is an arrangement of n2 numbers, usually distinct integers, in a square, such that the n numbers in all rows, all columns, and both diagonals sum to the same constant. A normal magic square contains the integers from 1 to n2. The term "magic square" is also sometimes used to refer to any of various types of word square.
Normal magic squares exist for all orders n ≥ 1 except n = 2, although the case n = 1 is trivial, consisting of a single cell containing the number 1. The smallest nontrivial case, shown below, is of order 3.
Spoiler:
 

______________________________________
[You must be registered and logged in to see this image.]

[You must be registered and logged in to see this image.]
[You must be registered and logged in to see this image.]
-[You must be registered and logged in to see this link.]<3 (Add me on FB)
Back to top Go down
View user profile
avatar
[FM]wapaklez
Head Moderator
Head Moderator

Posts : 26
EC-Points : 2065
Thanked : 6
Join date : 20/10/2011
Age : 25
Location : Philippines

PostSubject: Re: Magic Square Java   Mon Nov 21, 2011 5:32 pm

Nice Program! Pretty Cool! hihi... ^_^

______________________________________
[You must be registered and logged in to see this image.]

[You must be registered and logged in to see this image.]
[You must be registered and logged in to see this image.]
-[You must be registered and logged in to see this link.]<3 (Add me on FB)
Back to top Go down
View user profile
avatar
Admin[Mr.Anon14]
Admin
Admin

Posts : 50
EC-Points : 1064
Thanked : 4
Join date : 08/11/2011
Age : 20
Location : Somewhere can't be seen

Hacker's Info
Hacking Exp:
0/0  (0/0)
Hacker Type: White Hat
Hacking Title:

PostSubject: Re: Magic Square Java   Mon Nov 21, 2011 5:36 pm

SODUKO! xD

______________________________________
[You must be registered and logged in to see this image.]
Facebook Page : [You must be registered and logged in to see this link.]
Blog : [You must be registered and logged in to see this link.]
My Facebook : [You must be registered and logged in to see this link.]
Thanks For All Your Support, I Appreciated It All
Want More Helps?
Wait For Some Useful Posts or Request It!

I am Grey Phantom , "The Hidden Phantom Of The Generations."

[You must be registered and logged in to see this image.]
[You must be registered and logged in to see this image.]
Back to top Go down
View user profile http://darkages.canadianforum.net

Sponsored content



PostSubject: Re: Magic Square Java   

Back to top Go down
 

Magic Square Java

View previous topic View next topic Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
Elite Coders Society :: Software Development :: Java Programming :: Java Programming-

Protected by Copyscape Duplicate Content Finder
Powered By EliteCoders™

Elite Coders Partner Links
GreyPhantomYour Link HereYour Link HereYour Link Here
Yahoo!GoogleFacebookForumotion