Print number in ascending order which contains 1 , 2 and 3 in their digits . | C # program to print all number containing 1 , 2 and 3 in any order . ; prints all the number containing 1 , 2 , 3 in any order ; check if the number contains 1 , 2 & 3 in any order ; sort all the numbers ; convert the number to string and find if it contains 1 , 2 & 3. ; Driver Code
using System ; using System . Collections . Generic ; using System . Text ; class GFG { private static string printNumbers ( int [ ] numbers ) { List < int > array = new List < int > ( ) ; foreach ( int number in numbers ) { if ( findContainsOneTwoThree ( number ) ) { array . Add ( number ) ; } } array . Sort ( ) ; StringBuilder strbuf = new StringBuilder ( ) ; System . Collections . IEnumerator it = array . GetEnumerator ( ) ; while ( it . MoveNext ( ) ) { int value = ( int ) it . Current ; if ( strbuf . Length > 0 ) { strbuf . Append ( " , ▁ " ) ; } strbuf . Append ( Convert . ToString ( value ) ) ; } return ( strbuf . Length > 0 ) ? strbuf . ToString ( ) : " - 1" ; } private static bool findContainsOneTwoThree ( int number ) { string str = Convert . ToString ( number ) ; return ( str . Contains ( "1" ) && str . Contains ( "2" ) && str . Contains ( "3" ) ) ; } public static void Main ( string [ ] args ) { int [ ] numbers = new int [ ] { 123 , 1232 , 456 , 234 , 32145 } ; Console . WriteLine ( printNumbers ( numbers ) ) ; } }