Obviously you have already understand the problem.Is there another way to do what the "break label" does but for a simple if?

12-02-2011, 01:53 PM

Norm

Re: A simple question

Is the code trying to loop under a condition?
Write the code as a loop that continues looping as per the conditional requirement.

12-02-2011, 01:59 PM

chris.bos

Re: A simple question

Thnx Norm
but I forgot to mention that I have to wright this whole program without using while, do-while or for.So is there a command to replace
brake or do I have to find a complete different way to right the program?
Yes it will loop under condition.

12-02-2011, 02:05 PM

Norm

Re: A simple question

Your code looks like it should be in a loop.
What looping statements are you allowed to use?

Is this some trick about the way the variables' values are set and changed?
Can you replace the code on lines 4 to 11 with any code? Say just with an increment of z .

12-02-2011, 02:23 PM

chris.bos

Re: A simple question

Let me explain you cause i see that you are willing to help :D
it is a project for my uni.He want to make a program but we cant use while,do-while and for or we are going to fail.
the program asks the user to insert a number (it's on a previous part of the program) an it does this thing
for x=2
!
!!
for x =5
!
!!
!!!
!!!!
!!!!!
So as you can see i had to make a program that need a loop without been able to use any.And i thought of this trick.I don't want to change the program or have someone to make it for me cause i am very staborn and want to make all things by myself xD.
I just want to know (because i don't due to luck of experience) if there is a command that sends you some lines back in the program
(from line 13 to line 3)

12-02-2011, 02:30 PM

Norm

Re: A simple question

Quote:

a command that sends you some lines back in the program

That sounds like you are looking for a goto. That's banned in java.
Is the prof looking for a recursive method?

12-02-2011, 02:39 PM

chris.bos

Re: A simple question

Quote:

Originally Posted by Norm

Is the prof looking for a recursive method?

He does not ask for something specific :/
So i have to find an other way to make it work?
Pfff that's a mess :frusty:
Thnx anyway ;)

12-02-2011, 03:28 PM

Dark

Re: A simple question

If you can't use the usual looping methods, I would guess he wants you to use a recursive method. I don't know why for a simple project like this, but he's the teacher.

Do you know what recursion is?

12-02-2011, 05:28 PM

chris.bos

Re: A simple question

Quote:

Originally Posted by Dark

Do you know what recursion is?

Since i am learning java in an other language i don't know the meaning of "recursion" but if you mean the method that calls itself i used that and managed to solve the prob.Only when i came up with this method i understood what
Norm said. xD
Thnx tho! prob solved!

12-02-2011, 05:33 PM

Dark

Re: A simple question

Yes, recursion is essentially a method calling itself at the end. Incrementing a counter and whenever the counter is reached it breaks the recursion cycle. Recursion is essentially looping without using a predefined loop function.

12-02-2011, 05:49 PM

chris.bos

Re: A simple question

i Started learning java about a week ago,just for the project, so i didn't even know hot to make a recursion method.Looking in the book was the best I could do for this situation.Thnx for your help mates.It seems that i should start learning their English names too.

The main idea of recursion is breaking down your problem into "smaller chunks" until they are small enough to solve. Once these small problems are solved, they are traced back up to solve the bigger problem further up in the stack. Sorting algorithms such as the Quick Sort and the Merge Sort are programmed by using this programming technique.