Last Java programming questions

In summary,The Java program asks the user for 5 integers in the main method that are between 0 and 9, inclusive.The method called “permutations” accepts these 5 integers and prints all possible permutations for those numbers.Next, after this method is called, generate all possible permutations for (9 – 1st number), (9 – 2nd number), (9 – 3rd number), (9 – 4th number), and (9 – 5th number).For example, if the first time you entered the numbers (5, 6, 7, 8, 9), the second time the method is called the numbers will be (4, 3, 2, 1,
  • #1
JasonJo
429
2
Your task is to create a Java program with the name that asks the user for 5 integers in the main method that are between 0 and 9, inclusive. You should then write a method called “permutations” which accepts these 5 integers and prints all possible permutations for those numbers. (Hint: You will need 5 nested loops and an array to do this. Store the 5 numbers in an array inside the method and use the 5 loops to generate all possible array position combinations). Next, after this method is called, generate all possible permutations for (9 – 1st number), (9 – 2nd number), (9 – 3rd number), (9 – 4th number), and (9 – 5th number). For example, if the first time you entered the numbers (5, 6, 7, 8, 9), the second time the method is called the numbers will be (4, 3, 2, 1, 0). It is okay for this assignment if there are duplicate permutations that are printed.

And the next part is do the same problem but make sure there are no duplicate permutations.

i don't really know any discrete math, so any insight to this problem would be great.

i tried to conceptualize it in terms of switching indices of an array, but i don't quite know how to formulate it.
 
Physics news on Phys.org
  • #2
First, place the first element. This is your outer loop and you can place the outer element in five different positions: 0, 1, 2, 3, or 4. The outer loop counter can represent the current position of the first element.

Then, place the second element. The second element can have four different positions because when you come to the position where you already have the first element, you have to skip it for the second element.

Proceed similarly for the other elements.
 
  • #3
Actually, that method pretty much requires that you use a second array to store the temporary permutation as you go. If you want to just print it immediately without storing it again, then you can modify the method so that the x'th loop counter refers to the array index of the element to go at the x'th location.
 
  • #4
I like BicycleTree's suggestion, unless you're required to use nested loops for the learning value. Then again, you can use nested loops to print out a list of permutations of the letters a,b,c,d,e and then copy them into your program, having it store values for each letter. Perhaps you'll get extra credit for making it run faster :)
 

1. What is the purpose of "Last Java programming questions"?

The purpose of "Last Java programming questions" is to provide a set of questions that test a programmer's knowledge and understanding of Java programming concepts. These questions are typically used for job interviews, exams, or practice exercises.

2. How many questions are usually included in "Last Java programming questions"?

The number of questions included in "Last Java programming questions" can vary, but it typically includes a set of 25-50 questions. However, this may vary depending on the source or purpose of the questions.

3. Are "Last Java programming questions" only for advanced programmers?

No, "Last Java programming questions" can be used by both beginner and advanced programmers. The questions may range in difficulty, but they cover a variety of topics, making them suitable for programmers at all levels.

4. Can "Last Java programming questions" help me prepare for a Java certification exam?

Yes, "Last Java programming questions" can be a useful tool for preparing for a Java certification exam. They cover a wide range of topics and can help you identify any knowledge gaps you may have.

5. Are "Last Java programming questions" a good way to assess someone's Java skills?

Yes, "Last Java programming questions" can be a useful assessment tool for evaluating someone's Java skills. They cover a variety of topics and can give insight into a person's understanding and proficiency in Java programming.

Similar threads

Replies
5
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Programming and Computer Science
Replies
17
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
3K
  • Programming and Computer Science
Replies
16
Views
1K
  • Programming and Computer Science
Replies
4
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
12
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
21
Views
2K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
5
Views
1K
Back
Top