Hi all i need a piece of code that will find a value in an array and change it.

private int[][] level = new int[][]{ 	    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},	
												{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},	
												{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},	 
												{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},	
												{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},	
												{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},	
												{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},	
												{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},	
												{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},	
												{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},	
												{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3}	
	};

it needs to find the 1 and move it to the next square to the right, whlist replacing the orginal position with a 0.
thanks in advance :)

Member Avatar for ztini
public class Matrix {
	
	private static int[][] level = new int[][] { {0, 0 , 0}, {1, 0, 0}, {0, 0, 0}};
	
	public static void findTheOne() {
		
		boolean found = false;
		for (int i = 0; i < level.length; i++) {
			for (int j = 0; j < level[0].length; j++) {
				if (level[j][i] == 1) {
					level[j][i] = 0;
					if (i < level.length - 1)
						level[j][i+1] = 1;
					else if (j + 1 > level.length)
						level[0][0] = 1;
					else
						level[j+1][0] = 1;
					found = true;
					break;
				}
			}
			if (found) break;
		}
	}
	
	public static void main(String[] args) {
		Matrix.findTheOne();
	}
}
public class Matrix {
	
	private static int[][] level = new int[][] { {0, 0 , 0}, {1, 0, 0}, {0, 0, 0}};
	
	public static void findTheOne() {
		
		boolean found = false;
		for (int i = 0; i < level.length; i++) {
			for (int j = 0; j < level[0].length; j++) {
				if (level[j][i] == 1) {
					level[j][i] = 0;
					if (i < level.length - 1)
						level[j][i+1] = 1;
					else if (j + 1 > level.length)
						level[0][0] = 1;
					else
						level[j+1][0] = 1;
					found = true;
					break;
				}
			}
			if (found) break;
		}
	}
	
	public static void main(String[] args) {
		Matrix.findTheOne();
	}
}

ok ztini, what is the point of this post?
a person that has never posted here before asks a basic question, basically posts his homework here, and, not thinking about pointing him in the right direction, you just deliver some custom made code (logical error included, complementary off course) and by doing so ignoring the rules of the website.

Yes: we do encourage students to make some efforts on their own
Yes: we are willing to help them solve their problems
Yes: we want our new members to improve their skills

- but -

No: we are not 'developers-for-hire'
No: we do not encourage freeloading
No: we do not need the jobmarket to be overrun by incompetent developers

commented: Agreed +1
Member Avatar for ztini

Hi stultuske,

While I appreciate your enthusiasm towards the rules of this website, perhaps you should actually read them: http://www.daniweb.com/forums/faq.php?faq=daniweb_policies

Keep It Pleasant

Do not post anything with malicious intent against another member, including, but not limited to, racist, sexist or religiously prejudiced remarks
Do not post insults or personal attacks aimed at another member
Do not use offensive or obscene language
Do not try to bypass the DaniWeb inappropriate language filter

Furthermore, I thought this was a community for all developers...regardless of experience, aptitude, or number of posts previously made.

To address your concerns:
1) I didn't get paid.
2) I encourage new developers to look at code; this is an excellent way to learn. Scoffing at them with self-righteousness does nothing to procure their learning.
3) Sorry, I will not discourage new developers--incompetent or not.

If you don't like this, feel free to ignore my posts.

Have a pleasant day.

Hi I am fairly new to java and I'm sure it is a basic question but I'm not incompetent just because I didn't know how to do something, I probably know more about ASP & PHP then you will ever know, I am new to java programming language and I full thank the reply and I will try and implement later when I have the time I will let you know how I get on and any extra help will be greatly appreciated.
and I fully understand your not developers for hire but if someone choose to answer the question then they are fully allowed to he hasn't written the whole programme for me he has posted one method that I will learn from and implement.

Stultuske if you know of a better solution please do share, this is a learning commuinty

Hi stultuske,

While I appreciate your enthusiasm towards the rules of this website, perhaps you should actually read them: http://www.daniweb.com/forums/faq.php?faq=daniweb_policies

Keep It Pleasant

Do not post anything with malicious intent against another member, including, but not limited to, racist, sexist or religiously prejudiced remarks
Do not post insults or personal attacks aimed at another member
Do not use offensive or obscene language
Do not try to bypass the DaniWeb inappropriate language filter

Furthermore, I thought this was a community for all developers...regardless of experience, aptitude, or number of posts previously made.

To address your concerns:
1) I didn't get paid.
2) I encourage new developers to look at code; this is an excellent way to learn. Scoffing at them with self-righteousness does nothing to procure their learning.
3) Sorry, I will not discourage new developers--incompetent or not.

If you don't like this, feel free to ignore my posts.

Have a pleasant day.

It is true, there is nothing in the rules about it, afaik it is not a ban worthy offence. But it is frowned upon. You should just first ask a poster to show their code, where they are having problems, any errors etc. That way we know they are not just looking for an easy ride through life. Regarding the etiquette of the website, if you enter any of the dev forums here, at the top of the list of threads, you will see this message:

Our Software Development forum category encompasses topics related to application programming and software design. When posting programming code, encase it in (code), (code=syntax), where 'syntax' is any language found within our Code Snippets section, or (icode), for inline code, bbcode tags. Also, to keep DaniWeb a student-friendly place to learn, don't expect quick solutions to your homework. We'll help you get started and exchange algorithm ideas, but only if you show that you're willing to put in effort as well.

This is nothing to do with my course just something I was intrested in and my code displays the array in a text field and you press a button to move right the 1 moves right, when you press a button to move up the 1 moves up the error I have been getting when trying to do this myself was an unknown source error, but again thanks to first reply for trying to help, other clearly getting high and mighty because they don't have a solution

to clearify my answer:
this IS a learning forum, not a 'give-me-code' forum. whether you benefit or not, you are encouraging people to just ask you to do the code, without making an effort.

besides the fact that you're helping people passing their courses and become "certified"
developers, making t harder for other developers to find job, just handing out code also make sure that the lazy ones never will make an effort to learn anything, since.. what the hell for? you and some other people here will gladly hold their hands and do their homework for them

if this happens once, ok, bit of a nuissance, but if questions like this come practically every day ... yes, sometimes they do seriously bother you, especially if they're being encouraged. you've been a member for less than a month, so I do understand you haven't seen many of these requests passing by, but sooner or later. yes, it 'll bother you as well.

I will always help people when it is asked I understand that an explanation should have been given with the code and I didn't mean my question to come over as give-me-code and I have only been a member of 'this' forum for less than a month but I have been a member of web development forums f

bart, my answer was more directed towards ztini. but still, it would've been appreciated if you had posted some code of your own in your first post, together with info about where you were stuck or an error message you were getting, instead of just the description of what you need.

using a few for-loops and changing a value in an array is all you needed to know to get this fixed, you should have been able to have done most of it on your own, so I assumed you did have some code we could help you with and maybe correct, instead of just writing our own.

hi all, i have been able to use the code to modify my array in a way that i am finding very useful, however i have come unstuck somewhere else the array shown in the original post is used to put buttons onto a panel however once the array is modified i cannot redraw the buttons. i have tried center.removeAll() then my for loop which creates the buttons on the center panel, then this.repaint() but this leaves me with an empty panel. i wasnt sure which code to add so tell me what you need to see :)
i have a for loop which adds buttons to the panel in accordance to the array

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.