Question

I need help with this question in JAVA. I need the code, the UML diagram and...

I need help with this question in JAVA. I need the code, the UML diagram and the pseudocode Do a recursive method that return every possible k permutations of the String non-zeros number given Sample input : "123" , 2 output : "1-2", "1-3", "2-3", "2-1", "3-1", "3-2"

0 0
Add a comment Improve this question Transcribed image text
Answer #1

I am providing JAVA code for k possible permutations, as the input can be a digit or letter so I have not set any data type for that.

-------Code---------------------------

import java.util.Arrays;

public class Combination {
    public static void main(String[] args){
        String[] arr = {"1","2","3"};
        combinations2(arr, 3, 0, new String[3]);
    }

    static void combinations2(String[] arr, int len, int startPosition, String[] result){
        if (len == 0){
            System.out.println(Arrays.toString(result));
            return;
        }       
        for (int i = startPosition; i <= arr.length-len; i++){
            result[result.length - len] = arr[i];
            combinations2(arr, len-1, i+1, result);
        }
    }       
}

-------------------------------------------

The code above takes string array, where I have added 1,2,3 as you gave in the example, this will now print all the required permutation and combinations.

With the code, why there is need of pseudocode. If any doubt please comment. Please Upvote

----------------------------------Please Upvote----------------------------------------

Add a comment
Know the answer?
Add Answer to:
I need help with this question in JAVA. I need the code, the UML diagram and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • NEED HELP THE PROBLEM-SOLVING PROCESS WITH THE UML DIAGRAM + ACTIVITY DIAGRAMS TO RUN THE CODE...

    NEED HELP THE PROBLEM-SOLVING PROCESS WITH THE UML DIAGRAM + ACTIVITY DIAGRAMS TO RUN THE CODE PROGRAM PLEASE!! Problem1. (20 points) Recursive Coding Problem. Using the Problem Solving Process. Write a Java application that implements these two functions using recursive methods (recursion must be used). First Recursive Function. When one passes an integer as input (n for example), the return should return (output) the sum as follows: 1 + 1/2 + 1/3 + 1/4 + ... 1/(n-1) + 1/n Example:...

  • I need help with adding comments to my code and I need a uml diagram for...

    I need help with adding comments to my code and I need a uml diagram for it. PLs help.... Zipcodeproject.java package zipcodesproject; import java.util.Scanner; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class Zipcodesproject { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner input=new Scanner(System.in); BufferedReader reader; int code; String state,town; ziplist listOFCodes=new ziplist(); try { reader = new BufferedReader(new FileReader("C:UsersJayDesktopzipcodes.txt")); String line = reader.readLine(); while (line != null) { code=Integer.parseInt(line); line =...

  • JAVA PLEASE HELP The following is a UML diagram for a class. Write the code for...

    JAVA PLEASE HELP The following is a UML diagram for a class. Write the code for this class. Cat - breed : String - color : Color - name : String + Cat( name : String) + Cat(name : String, breed : String, color : Color) + getName() : String + getColor() : Color + getBreed() : String setColor(Color) setBreed(Breed) toString()

  • The current code I have is the following: package uml; public class uml {        public...

    The current code I have is the following: package uml; public class uml {        public static void main(String[] args) {              // TODO Auto-generated method stub        } } class Account { private String accountID; public Account(String accountID) { this.accountID = accountID; } public String getAccountID() { return accountID; } public void setAccountID(String accountID) { this.accountID = accountID; } @Override public String toString() { return "Account [accountID=" + accountID + "]"; } } class SuppliesAccount extends Account { private...

  • Create a UML diagram to help design the class described in exercise 3 below. Do this...

    Create a UML diagram to help design the class described in exercise 3 below. Do this exercise before you attempt to code the solution. Think about what instance variables will be required to describe a Baby class object; should they be private or public? Determine what class methods are required; should they be private or public? Write Java code for a Baby class. A Baby has a name of type String and an age of type integer. Supply two constructors:...

  • Java class quiz need help~ This is the Backwards.java code. public class Backwards { /** *...

    Java class quiz need help~ This is the Backwards.java code. public class Backwards { /** * Program starts with this method. * * @param args A String to be printed backwards */ public static void main(String[] args) { if (args.length == 0) { System.out.println("ERROR: Enter a String on commandline."); } else { String word = args[0]; String backwards = iterativeBack(word); // A (return address) System.out.println("Iterative solution: " + backwards); backwards = recursiveBack(word); // B (return address) System.out.println("\n\nRecursive solution: " +...

  • Java, please. Work based on the code above. DESCRIPTION: The purpose of this question is offload...

    Java, please. Work based on the code above. DESCRIPTION: The purpose of this question is offload processing from the main method to a static helper method. You will be given the main method. Do not alter this code. Your goal is to write a new method called oddOneOut, which will accept a String, and print it in out every other letter. For example, if the String was "abcdefghijk", the oddOneOut method will return "acegik" METHOD INPUT: • A string METHOD...

  • in java language please Question 2 (14 marks) a) Complete the following UML diagram as lava...

    in java language please Question 2 (14 marks) a) Complete the following UML diagram as lava classes (8 marks): Write a constructor for Computer ser class based on the information you have in the UML Complete the hasSpaces method to check if a string has space or not il. Extend ComputerUser class with two subclasses, as shown below in UML diagram and write the appropriate methods listed in the UML diagram <<abstract>> ComputerUser # username: String #password: String + Computer...

  • Draw the UML DIAGRAM ALSO PLEASE DRAW THE UML DIAGRAM.ALSO in java should use the program in java For this task you will create a Point3D class to represent a point that has coordinates in thr...

    Draw the UML DIAGRAM ALSO PLEASE DRAW THE UML DIAGRAM.ALSO in java should use the program in java For this task you will create a Point3D class to represent a point that has coordinates in three dimensions labeled x, y and z. You will then use the class to perform some calculations on an array of these points. You need to draw a UML diagram for the class (Point3D) and then implement the class The Point3D class will have the...

  • I need help putting These in correct order. Java please rearrange the following code into a...

    I need help putting These in correct order. Java please rearrange the following code into a working program based on the expected output. HINT: Use JDoodle to help in verifying the expected output 3. String D books new String 3 System.out.printinfbooks[refsl)h Int ref while (z < 3) System.out.print("books #*): books [0] "Grapes of wrath"; class BookArrays f books [1] Wind"; "Gone With The public static void main (String I ares) int z 0; 22+1; ref- title[2] int [I title new...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT