473,399 Members | 3,401 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Spiral Matrix

hi
i want a java source code for spiral matix
if we give a input matrix as
1 2 3
4 5 6
7 8 9
so the output matrix should be
2 3 4
5 6 7
8 9 1

Or

9 1 2
3 4 5
6 7 8
i hope you will help for this.....
Apr 4 '10 #1
1 3056
jkmyoung
2,057 Expert 2GB
One possible method:
Think of the indices:
0 -> [0][0]
1 -> [0][1]
2 -> [0][2]
3 -> [1][0]
4 -> [1][1]
5 -> [1][2]
6 -> [2][0]
7 -> [2][1]
8 -> [2][2]

Formula for i -> x, y
x = i / 3;
y = i % 3;

To shift one position, add or subtract one from i, and do the same conversion (with minor modification) to x and y.
Apr 5 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Ben Ingram | last post by:
Hi all, I am writing a template matrix class in which the template parameters are the number of rows and number of columns. There are a number of reasons why this is an appropriate tradeoff for...
2
by: Usman | last post by:
Hello Everyone. Can some one help me on this question , I studied a lot but still am unable to do this I need to print the following pattern using recursion in C++ , the end term is ' n '...
2
by: sid1 | last post by:
hi i have devised the source code for generating spiral matrix in C++..its compiling properly but i run it it is giving some segmentation fault plz help me how shud i remove this error. thanx
2
by: MBeckford05 | last post by:
Hello There ! I would like help, in writing a Java program to output an Archimedean Spiral to the screen. I have read on the net what a Archiemedian Spiral is. But I'm not too familiar with...
3
by: MBeckford05 | last post by:
Hi Everyone, I am placed with a problem. How to write a program in Java to produce the Archimeadean Spiral. The progam should look like an Archimedean spiral on the screen. Any help in hoe to...
8
by: mail2sandeepnl | last post by:
Hi how to spirally access 2 d array, ex: for input array 1 2 3 4 5 6 7 8 9 10 11 12 output should be like : 1,2,3,4,8,12,11,10,9,5,6,7
4
by: sumuka | last post by:
Hello , Im doing a java project in java 1.5 version and i need to draw the spiral . The problem is the user has to draw a box or rectangle of any size on an image and the central point of that box...
1
by: sumuka | last post by:
Hello, Can Anybody tell me how to draw a simple spiral in java ? Thanks in anticipation,
1
by: sumuka | last post by:
Hello, I'm doing a java project in which I have a rectangle which is drawn by the user by dragging the mouse and hence the size of the rectangle can vary for each execution. Now i need to draw a...
4
Thekid
by: Thekid | last post by:
Hi, I'm not very good with javascript but I wanted to know if there was a simple way to change this code so instead of printing out the numbers & letters in a spiral on the page, it can be changed to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.