Print the numbers between 30 to 3000.

Microsoft Interview Question Developer Program Engineers

看到一个题目比较有意思:

Print the numbers between 30 to 3000. 

CONSTRAINT: 
The numbers shouldnt contain digits either in incresing order or decreasing order. 

FOLLOWING NOT ALLOWED 
##123,234,345,1234,2345##increasing order, 
##32,21,321,432,3210 etc##decresing order. 

FOLLOWING ALLOWED: 
243,27,578,2344 etc., 
Now see who ll code ths....

答案是:

1 String sortedNumbers = "123456789 9876543210";
2         for (int i = 31; i <= 3000; i++) {
3             String temp = "" + i;
4             if (!sortedNumbers.contains(temp)) {
5                 System.out.println(temp);
6             }
7         }

 

 

posted on 2013-10-05 14:20  walkwalkwalk  阅读(290)  评论(0编辑  收藏  举报

导航