• Post Reply Bookmark Topic Watch Topic
  • New Topic

method and parameters  RSS feed

 
Aaron Brad
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
numbers allowed: 1 to 6.
Here is my code for 7+ puzzle: it shows two numbers that add upto 7.

public class nestedfor
{
public static void main(String[] args)
{
for(int i=1; i<=7; i++)
{
for(int j=1; j<=6; j++)
{
if(i+j==7)
{
System.out.println(i+ " " +j);
}
}
}
}
}

Now...the question is:
Reusing code from your 7+ program, write a method that takes as a
parameter a number that is required and prints out all the permutations that
add up to that number.


How do i do it? anyone please help?
 
Tim Cooke
Marshal
Posts: 4051
239
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to The Ranch Aaron,

When posting code on The Ranch it is recommended to UseCodeTags (<- click). Which means putting your code inbetween [code ] tags. It makes your post much easier to read, and as such more people will read it.

This looks very much like some homework. In which case there are a couple Ranch policies that you should be aware of:
1) DoYourOwnHomework (<- click the link)
2) ShowSomeEffort (<- click the link)

In short, we will gladly help you with homework, but you have to have a go yourself first and show us what you've tried and explain clearly what particular problem you're having trouble with.

Good questions elicit good and plentiful answers. Have a read of HowToAskQuestionsOnJavaRanch
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!