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 †
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.
 
HomeForumMagic Square Java 2a512xyPortalLatest imagesGalleryMagic Square Java Dw6hztSearchMagic Square Java 2ns506pMagic Square Java 2dt2b75RegisterLog 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
Admin[dElmARk]
Admin[dElmARk]
Forum Owner
Forum Owner

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

Hacker's Info
Hacking Exp:
Magic Square Java Left_bar_bleue0/0Magic Square Java Empty_bar_bleue  (0/0)
Hacker Type: White Hat
Hacking Title:

Magic Square Java Empty
PostSubject: Magic Square Java   Magic Square Java EmptyMon 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();
    }
   }
}
Back to top Go down
Admin[Mr.Anon14]
Admin[Mr.Anon14]
Admin
Admin

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

Hacker's Info
Hacking Exp:
Magic Square Java Left_bar_bleue0/0Magic Square Java Empty_bar_bleue  (0/0)
Hacker Type: White Hat
Hacking Title:

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

What is Magic Square?
Back to top Go down
http://darkages.canadianforum.net
[FM]wapaklez
[FM]wapaklez
Head Moderator
Head Moderator

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

Magic Square Java Empty
PostSubject: Re: Magic Square Java   Magic Square Java EmptyMon 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:
Back to top Go down
[FM]wapaklez
[FM]wapaklez
Head Moderator
Head Moderator

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

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

Nice Program! Pretty Cool! hihi... ^_^
Back to top Go down
Admin[Mr.Anon14]
Admin[Mr.Anon14]
Admin
Admin

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

Hacker's Info
Hacking Exp:
Magic Square Java Left_bar_bleue0/0Magic Square Java Empty_bar_bleue  (0/0)
Hacker Type: White Hat
Hacking Title:

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

SODUKO! xD
Back to top Go down
http://darkages.canadianforum.net

Sponsored content



Magic Square Java Empty
PostSubject: Re: Magic Square Java   Magic Square Java Empty

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