|
| Author | Message |
---|
Admin[dElmARk] Forum Owner
Posts : 78 EC-Points : 6304 Thanked : 21 Join date : 15/10/2011 Age : 29 Location : Philippines
Hacker's Info Hacking Exp: (0/0) Hacker Type: White Hat Hacking Title:
| Subject: 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(); } } } |
| | | Admin[Mr.Anon14] Admin
Posts : 50 EC-Points : 1064 Thanked : 4 Join date : 08/11/2011 Age : 28 Location : Somewhere can't be seen
Hacker's Info Hacking Exp: (0/0) Hacker Type: White Hat Hacking Title:
| Subject: Re: Magic Square Java Mon Nov 21, 2011 4:58 pm | |
| |
| | | [FM]wapaklez Head Moderator
Posts : 26 EC-Points : 2065 Thanked : 6 Join date : 20/10/2011 Age : 32 Location : Philippines
| Subject: 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.]The constant sum in every row, column and diagonal is called the magic constant or magic sum, M. The magic constant of a normal magic square depends only on n and has the value [You must be registered and logged in to see this image.]
|
| | | [FM]wapaklez Head Moderator
Posts : 26 EC-Points : 2065 Thanked : 6 Join date : 20/10/2011 Age : 32 Location : Philippines
| Subject: Re: Magic Square Java Mon Nov 21, 2011 5:32 pm | |
| Nice Program! Pretty Cool! hihi... ^_^ |
| | | Admin[Mr.Anon14] Admin
Posts : 50 EC-Points : 1064 Thanked : 4 Join date : 08/11/2011 Age : 28 Location : Somewhere can't be seen
Hacker's Info Hacking Exp: (0/0) Hacker Type: White Hat Hacking Title:
| Subject: Re: Magic Square Java Mon Nov 21, 2011 5:36 pm | |
| |
| | | Sponsored content
| Subject: Re: Magic Square Java | |
| |
| | | |
Similar topics | |
|
Page 1 of 1 | |
| Permissions in this forum: | You cannot reply to topics in this forum
| |
| |
| Latest topics | » Free all Premium Accounts 06.09.2014. Uploaded,Depositfiles,Keep2shar,Terafile,Bitshare eand moreSat Sep 06, 2014 2:17 am by claves » Free all Premium Accounts16.08.2014. Uploaded,Rapidgator,Depositfiles,Keep2share,Novafile,Share-Online,JDownloader2 and moreFri Aug 15, 2014 5:29 pm by claves » All Premium Accounts and cookie 17.04.2014.Wed Apr 16, 2014 7:38 pm by claves » All Premium Account and coocie 16.04.2014.Tue Apr 15, 2014 11:14 pm by claves » i am stuck in this please help me this is my first timeSun Mar 16, 2014 6:58 pm by anum bakhtiar » Free all Premium Accounts 25.12.13.Rapidgator,Lumfile,Filefactory,Freakshare, Netload,Extabit,Bitshare,Premium Cookies and Premium Javascript Wed Dec 25, 2013 3:05 am by claves » Free all Premium Accounts 17.11.13.- Uploaded,Rapidgator,Depositfiles,Extabit,JDownloader2,Premium Cookies and Premium Javascript Sat Nov 16, 2013 6:56 pm by claves » Free all Premium Accounts, Premium Cookies and Premium Javascript 15.10.13.Mon Oct 14, 2013 2:26 pm by claves » Free all Premium Accounts, Premium Cookies and Premium Javascript 08.10.13.Mon Oct 07, 2013 11:39 pm by claves |
Who is online? | In total there are 7 users online :: 0 Registered, 0 Hidden and 7 Guests None Most users ever online was 23 on Sun Jun 25, 2017 2:06 pm |
|