Question

In: Computer Science

IN JAVA PLEASE Implement a recursive approach to showing all the teams that can be created...

IN JAVA PLEASE

Implement a recursive approach to showing all the teams that can be created from a group (n things taken k at a time). Write the recursive showTeams()method and a main() method to prompt the user for the group size and the team size to provide arguments for showTeam(), which then displays all the possible combinations.

Solutions

Expert Solution

Program code screenshot

Program Sample Input/Output Screenshot

Program Code to copy

import java.util.*;
public class Main {


   //current_person refers the the current person in the group who will 
   //either be taken in the team or not taken in the team
   //current_team_size refers to the number of person who are already a part of the team
   public static void showAllTeams(int groupSize, int teamSize, int current_person, int current_team_size, String current_team){
      //base case is if we have sufficient menber to make a team
      if(current_team_size==teamSize){
         //printthe team and return
         System.out.println(current_team);
         return;
      }else if(current_person>groupSize){
         //this means we have checked all the people in the group
         return;
      }
      //if he is in the team then add him/her in team then check next person
      //also increment current_team_size
      showAllTeams(groupSize, teamSize, current_person+1, current_team_size+1, current_team+current_person+" ");

      //here we have an option of either taking the current_person in the team or not
      //if he/she is not in the team check next person
      showAllTeams(groupSize, teamSize, current_person+1, current_team_size, current_team);
   }
   public static void main(String[] args) {
      int groupSize, teamSize;
      Scanner sc = new Scanner(System.in);
      System.out.print("Enter group size: ");
      groupSize=sc.nextInt();
      System.out.print("Enter team size: ");
      teamSize=sc.nextInt();
      sc.close();
      showAllTeams(groupSize, teamSize, 1, 0, "");
   }
}

Related Solutions

JAVA PLEASE Write a recursive function that does the following: Given a number, add all the...
JAVA PLEASE Write a recursive function that does the following: Given a number, add all the digits and display the sum. Example: ​​The sum of the number 5432 would be 14. o Do not use the static modifier. No global variables. Your program should implement a non-tail recursive algorithm. In other words, it should do something as it moves towards the base case, the tail, and also do something as it comes back from the tail to the beginning. o...
Please write in java: Write a recursive method toNumber that forms the integer sum of all...
Please write in java: Write a recursive method toNumber that forms the integer sum of all digit characters in a string. For example, the result of toNumber("3ac4") would be 7. Hint: If next is a digit character ('0' through '9'), Character.isDigit(next) is true and the numeric value of next is Character. digit(next, 10).
Please use java language Thanks! Implement a recursive method called "pow" that takes 2 integers, x...
Please use java language Thanks! Implement a recursive method called "pow" that takes 2 integers, x and y, as parameters and returns the value xy (x raised to the power y). The exponent must be non-negative. If a negative argument is given for the exponent, then an exception should be thrown. Implement a recursive method called "fib" that takes a positive integer, n, as a parameter and returns the nth Fibonacci value. Assume that the first 2 values in the...
-----xxxxx-------Could you please use java language. thank you. :::::: XXXX::::::::::: Implement a recursive reverse sorting algorithm....
-----xxxxx-------Could you please use java language. thank you. :::::: XXXX::::::::::: Implement a recursive reverse sorting algorithm. The following requirements should meet: a The program shall graphically prompt the user for a file. bThe program shall read the selected file which will contain 1 integer per line. c. The program shall sort the values it reads from the file from largest to smallest. d.The program shall write the values to an output file from largest to smallest in the same directory...
All code in JAVA please 1. Implement Insertion Sort 2. Implement Selection Sort *For problem 1...
All code in JAVA please 1. Implement Insertion Sort 2. Implement Selection Sort *For problem 1 and 2, please: a. Let the program generate a random array. b. Output both the original random array and the sorted version of it
Java String search Design and implement a recursive version of a binary search.  Instead of using a...
Java String search Design and implement a recursive version of a binary search.  Instead of using a loop to repeatedly check for the target value, use calls to a recursive method to check one value at a time.  If the value is not the target, refine the search space and call the method again.  The name to search for is entered by the user, as is the indexes that define the range of viable candidates can be entered by the user (that are...
JAVA - PLEASE COMMENT CODE - THANK YOU: Implement a program that can input an expression...
JAVA - PLEASE COMMENT CODE - THANK YOU: Implement a program that can input an expression in postfix notation and output its value.
Problem 2 Write a program in Java to implement a recursive search function int terSearch(int A[],...
Problem 2 Write a program in Java to implement a recursive search function int terSearch(int A[], int l, int r, int x) that returns the location of x in a given sorted array of n integers A if x is present, otherwise -1. The terSearch search function, unlike the binary search, must consider two dividing points int d1 = l + (r - l)/3 int d2 = d1 + (r - l)/3 For the first call of your recursive search...
Problem 3: (a) Implement a sublinear running time complexity recursive function in Java public static long...
Problem 3: (a) Implement a sublinear running time complexity recursive function in Java public static long exponentiation(long x, int n) to calculate x^n. Note: In your function you can use only the basic arithmetic operators (+, -, *, %, and /). (b) What is the running time complexity of your function? Justify. (c) Give a number of multiplications used by your function to calculate x^63. Important Notes: • For the item (a): o You must add the main method in...
(Java) Please describe how API's can be created using abstract classes, interfaces and regular classes.
(Java) Please describe how API's can be created using abstract classes, interfaces and regular classes.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT