class PhoneSpel { static char numlets[][] = { { '0' }, { '1' }, { 'a', 'b', 'c' }, { 'd', 'e', 'f' }, { 'g', 'h', 'i' }, { 'j', 'k', 'l' }, { 'm', 'n', 'o' }, { 'p', 'q', 'r', 's' }, { 't', 'u', 'v' }, { 'w', 'x', 'y', 'z' } }; public static void main( String argv[] ) { String num = argv[0]; int nums[] = new int[num.length()]; int inds[] = new int[num.length()]; int p = 0; int count = 0; for ( int i = 0; i < num.length(); i++ ) { nums[p] = num.charAt( i ) - '0'; if ( nums[p] >= 0 && nums[p] <= 9 ) { p++; } } System.out.print("for number:"); for ( int i = 0; i < p; i++ ) { System.out.print( nums[i] ); } System.out.println(); while ( true ) { int incp; count++; for ( int i = 0; i < p; i++ ) { System.out.print( numlets[nums[i]][inds[i]] ); } System.out.println(); incp = p - 1; inds[incp]++; while ( inds[incp] >= numlets[nums[incp]].length ) { inds[incp] = 0; incp--; if ( incp < 0 ) { System.out.println( count + " words formed" ); return; } inds[incp]++; } } } };