一道淘汰85%面试者的百度开发者面试题

时间:2024-10-07 20:32:58 学人智库 我要投稿
  • 相关推荐

一道淘汰85%面试者的百度开发者面试题

  /**

一道淘汰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.unjs.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