Combination of Numbers coderinme

Combination of Numbers coderinme

Let us now code something based on numbers. Such as, We can create a kind of puzzle by jumbling some of the digits. In other words we can mix and match different digits to create different numbers in the number system.
For example : We are now going to print print all the possible combinations using the three digits – 1, 2, and 3. It is just like the numbers obtained could be 123, 231, 213, 231,132,312, 321.
Print all combination from 1 2 3

Write a program to accept three digits (i.e. 0 – 9) and print all its possible combinations.
Program:

import java.io.*;
public class Q14 
{
public static void main(String[] args) throws IOException 
{
BufferedReader inp=new BufferedReader(new InputStreamReader(System.in));
int a[]=new int[3];
System.out.print("Please enter the three digit i.e(0-9): ");
for(int k=0;k<3;k++) 
{
a[k]=Integer.parseInt(inp.readLine());
}
System.out.println("Possible combination are:");
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
for(int k=0;k<3;k++) 
{
if(i!=j&&i!=k&&j!=k)
System.out.print(" "+a[i]+a[j]+a[k]);
}
}
}

For more programs on Java, visit our Java Archives

Combination

All rights reserved. No part of this Post may be copied, distributed, or transmitted in any form or by any means, without the prior written permission of the website admin, except in the case of brief quotations embodied in critical reviews and certain other noncommercial uses permitted by copyright law. For permission requests, write to the owner, addressed “Attention: Permissions Coordinator,” to the admin @coderinme

Leave a reply:

Your email address will not be published.