- 相關推薦
一道淘汰85%面試者的百度開發者面試題
/**
* 依序遍歷0到100閉區間內所有的正整數,
* 如果該數字能被3整除,則輸出該數字及‘*’標記;
* 如果該數字能被5整除,則輸出該數字及‘#’標記;
* 如果該數字既能被3整除又能被5整除,則輸出該數字及‘*#’標記。
*/
public class Print {
public static void main(String[] args){
new Print().prints();
}
private void prints(){
for(int i = 1;i <= 100;i++){
String txt = "";
int flag = 0;
if (op3(i)){
flag += 1;
}
if (op5(i)){
flag += 2;
}
switch (flag){
case 1:txt = "*";break;
case 2:txt = "#";break;
case 3:txt = i+"#";break;
}
System.out.println("當前數字:" + i + "---->" + txt);
}
}
private boolean op3(int i){
if (i % 3 == 0) {
return true;
}
return false;
}
private boolean op5(int i) {
if (i % 5 == 0) {
return true;
}
return false;
}
}
http://www.gydabaoji.com/【一道淘汰85%面試者的百度開發者面試題】相關文章:
你可以知道面試題對求職者的重要性08-02
Microsoft面試題09-04
iOS面試題07-10
公司面試題09-12
hibernate面試題10-18
英語面試題精選06-13
小升初面試題06-10
PHP面試題10-14
面試遭淘汰的四大主因08-30
開發者薪資調查:程序員們的錢花哪了06-12