Computer Science, asked by ayaankabir2000, 1 month ago

Write a program in Java to accept a four-letter word. Display all the probable four letter combinations such that no letter should be repeated in the output within each combination.

Sample Input:
PARK

Sample Output:
PAKR, PKAR, PRAK, APRK, ARPK, AKPR, and so on.
MENTION THE VARIABLE DESCRIPTION TABLE AS WELL

Answers

Answered by chakrabortyaliva22
6

Answer:

import java.util.Scanner;

public class KboatStringCombinations

{

public static void main(String args[]) {

Scanner in = new Scanner(System.in);

System.out.println("Enter a word:");

String str = in.nextLine();

int len = str.length();

if (len != 4) {

System.out.println("Invalid Input!");

System.out.println("Please enter a four letter word");

return;

}

for (int i = 0; i < len; i++) {

for (int j = 0; j < len; j++) {

for (int k = 0; k < len; k++) {

for (int l = 0; l < len; l++) {

if (i != j && i != k && i != l

&& j != k && j != l

&& k != l) {

System.out.print(str.charAt(i));

System.out.print(str.charAt(j));

System.out.print(str.charAt(k));

System.out.println(str.charAt(l));

}

}

}

}

Explanation:

Ayaan ji ..

main sham ko or baat nhi kr paungi

aap subha ko link share kijiye ga plz!

or hn

aap kaise hai ?

Answered by madhudevi2508
3

Answer:

Explanation:

import java.util.Scanner;

public class KboatStringCombinations

{

public static void main(String args[]) {

Scanner in = new Scanner(System.in);

System.out.println("Enter a word:");

String str = in.nextLine();

int len = str.length();

if (len != 4) {

System.out.println("Invalid Input!");

System.out.println("Please enter a four letter word");

return;

}

for (int i = 0; i < len; i++) {

for (int j = 0; j < len; j++) {

for (int k = 0; k < len; k++) {

for (int l = 0; l < len; l++) {

if (i != j && i != k && i != l

&& j != k && j != l

&& k != l) {

System.out.print(str.charAt(i));

System.out.print(str.charAt(j));

System.out.print(str.charAt(k));

System.out.println(str.charAt(l));

}

}

}

}

}

}

}

Similar questions