Results 1 to 12 of 12
Thread: A simple question
- 12-02-2011, 12:41 PM #1
A simple question
Well i don't know how to name the post but this looks good.
Here is a piece of code!
}Java Code:int z=1; int j=1; label1: if (x>1){ System.out.print("!"); j++; if (j>z){ j=1; z++; System.out.println( ); } if (z<=x) break label1;
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, 12:53 PM #2
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, 12:59 PM #3
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.Last edited by chris.bos; 12-02-2011 at 01:06 PM.
- 12-02-2011, 01:05 PM #4
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, 01:23 PM #5
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, 01:30 PM #6
Re: A simple question
That sounds like you are looking for a goto. That's banned in java.a command that sends you some lines back in the program
Is the prof looking for a recursive method?
- 12-02-2011, 01:39 PM #7
- 12-02-2011, 02:28 PM #8
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?- Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
- +Rep people for helpful posts.
- 12-02-2011, 04:28 PM #9
Re: A simple question
- 12-02-2011, 04:33 PM #10
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.
- Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
- +Rep people for helpful posts.
- 12-02-2011, 04:49 PM #11
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.
- 12-02-2011, 05:37 PM #12
Member
- Join Date
- Dec 2011
- Posts
- 19
- Rep Power
- 0
Re: A simple question
When someone mentions recursion two things should immediately pop into your head.
Firstly: Recursive Call
Secondly: Base Case
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.
Similar Threads
-
simple question
By agater in forum New To JavaReplies: 5Last Post: 11-07-2011, 02:22 AM -
Simple question...
By Onyx in forum New To JavaReplies: 10Last Post: 08-10-2011, 10:44 PM -
Simple question
By Qsc in forum New To JavaReplies: 6Last Post: 03-06-2011, 11:24 PM -
Simple Question
By stackptr89 in forum New To JavaReplies: 13Last Post: 01-29-2011, 05:35 PM -
some simple question?
By jperson in forum New To JavaReplies: 4Last Post: 05-03-2010, 05:32 PM


LinkBack URL
About LinkBacks
Reply With Quote


Bookmarks