175k views
5 votes
Output all combinations of character variables a, b, and c. If a = 'x', b = 'y', and c = 'z', then the output is: xyz xzy yxz yzx zxy zyx Your code will be tested in three different programs, with a, b, c assigned with 'x', 'y', 'z', then with '#', '$', '%', then with '1', '2', '3'.

1 Answer

2 votes

Answer & Explanation:

//written in java

public class Main {

public static void main(String[] args) {

//declare a char variable for a, b, c

char a;

char b;

char c;

//assign a b and c

//a b and c can be replaced for with

// '#', '$', '%', then with '1', '2', '3'

// for further testing

a = 'x';

b = 'y';

c = 'z';

//output for all possible combination for a, b, c.

System.out.println("" + a + b + c + " " + a + c + b + " " + b + a + c +

" " + b + c + a + " " + c + a + b + " " + c + b + a);

}

}

User Masudul
by
3.5k points