Topics Index

Weekend Hack 26th Jan 2013 - 2 - Rs. 250 has these questions

Get the list of all the words possible with the characters provided

Write a program to return the list of all the words possible with the characters provided. The list should be sorted in ascending order. Do not use String or StringBuffer or Arrays or any other advanced classes. Only use character arrays for solving this.
Input (Char Array) Output (Two Dimensional Char Array)
{M, Y} {{M, Y},
{Y, M}}
{B, A, T} {{A, B, T},
{A, T, B},
{B, A, T},
{B, T, A},
{T, A, B},
{T, B, A}}
{M, O, N} {{M, N, O},
{M, O, N},
{N, M, O},
{N, O, M},
{O, M, N},
{O, N, M}}
{J, U, B, A} {{A, B, J, U},
{A, B, U, J},
{A, J, B, U},
{A, J, U, B},
{A, U, B, J},
{A, U, J, B},
{B, A, J, U},
{B, A, U, J},
{B, J, A, U},
{B, J, U, A},
{B, U, A, J},
{B, U, J, A},
{J, A, B, U},
{J, A, U, B},
{J, B, A, U},
{J, B, U, A},
{J, U, A, B},
{J, U, B, A},
{U, A, B, J},
{U, A, J, B},
{U, B, A, J},
{U, B, J, A},
{U, J, A, B},
{U, J, B, A}}
class GetAllCharCombinations

{    public static void main(String s[])
        char input[] = {'B', 'A', 'T'};
        char[][] words = getAllCombinations(input);
        for (char[] word : words) {
        for (char letter : word) {


public static char[][] getAllCombinations(char word[]) {
//Write code here to get all the combinations of the given word.

//If required write any additional methods here

Objects and References

What will be the output of the following program.
class BikeTester
    public static void main(String s[])
        Bike bike; = "Hero Honda";
        bike.model = "Shine"; = 125;
        bike.mileage = 72.5;
        bike.diskBrakes = false;

        System.out.println( + "'s " + bike.model + " gives a mileage of " + bike.mileage + "kmpl.");
class Bike
    String company;
    String model;
    int cc;
    double mileage;
    boolean diskBrakes;
A. Hero Honda's Shine gives a mileage of 72.5kmpl.
B. Compilation error - since Bike class has two Strings - company and model.
C. Runtime Error - NullPointerException since the bike object is not created.
D. Compilation error - since Bike class does not have a constructor.

© meritcampus 2019

All Rights Reserved.

Open In App