阿里巴巴校园招聘在线面试之附加题
写在前面:
题目一:
思路:
代码:
public static void printRandomNum(){Random random=new Random();int len=1001;int arr[]=new int[len];for(int i=1;i<len;i++)arr[i]=i;int randomNum=0;for(int i=0;i<900;i++){randomNum=random.nextInt(1000)+1;while(arr[randomNum]==0)randomNum=random.nextInt(1000)+1;System.out.print(randomNum+"\t");arr[randomNum]=0;if(i%10==9)System.out.println();}}
结果:
题目二:
思路:
代码:
//put apple thread
class PutThread extends Thread {PutGetDemo putGetDemo;public PutThread(PutGetDemo putGetDemo) {this.putGetDemo = putGetDemo;}public void run() {while (true) {putGetDemo.putApple();// put an apple}}
}// get apple thread
class GetThread extends Thread {PutGetDemo putGetDemo;public GetThread(PutGetDemo putGetDemo) {this.putGetDemo = putGetDemo;}public void run() {while (true) {putGetDemo.getApple();// get an apple}}
}public class PutGetDemo {private final int MAX_SIZE = 5;// the max num of apples in the boxprivate int produceNum = 0;private List<Integer> list = new ArrayList<Integer>();// to store the apples// put apple into the boxpublic synchronized void putApple() {int appleNum = 0;while (list.size() + 1 > MAX_SIZE) {System.out.println("the box is full");try {this.wait();} catch (InterruptedException e) {e.printStackTrace();}}appleNum = produceNum % 5 + 1;// the apple numberlist.add(appleNum);System.out.println("Push apple:" + appleNum);produceNum++;System.out.println("I have put an apple into box!");notify();}// //get the apple from the boxpublic synchronized void getApple() {while (list.size() == 0) {System.out.println("The box is empty");try {this.wait();} catch (InterruptedException e) {// TODO Auto-generated catch blocke.printStackTrace();}}System.out.println("Get apple: " + list.get(0));list.remove(0);System.out.println("I have get an apple!");notify();}public static void main(String[] args) {// TODO Auto-generated method stubPutGetDemo putGetDemo = new PutGetDemo();PutThread putThread = new PutThread(putGetDemo);// the put apple threadGetThread getThread = new GetThread(putGetDemo);// the get apple threadputThread.start();getThread.start();//CreateRandomNum.printRandomNum();}}
结果:
阿里巴巴校园招聘在线面试之附加题相关推荐
- vivo2020届春季校园招聘在线编程考试--[编程题]vivo智能手机产能
vivo2020届春季校园招聘在线编程考试--[编程题]vivo智能手机产能 题目 解题思路 代码块 题目 在vivo产线上,每位职工随着对手机加工流程认识的熟悉和经验的增加,日产量也会不断攀升. 假 ...
- vivo2020届春季校园招聘在线编程考试--[编程题]数位之积
vivo2020届春季校园招聘在线编程考试--[编程题]数位之积 题目 解题思路 代码块 题目 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 256M,其他语言512M 现给定任意正 ...
- 阿里巴巴 java附加题_阿里巴巴2014校园招聘研发笔试JAVA附加题一
3.对于经继承关系的类的执行顺序:父类静态代码块和变量->子类静态代码块和变量->父类非静态代码块->父类构造函数->->子类非静态代码块->子类构造函数 4.详细 ...
- 阿里巴巴校园招聘2019面试总结
写在前面 面的岗位是c++开发,二面跪了,但依然想些出来分享一下. 博主4月份开始着手找实习,期间面过两次阿里都挂在第一面,7月份至今在科大讯飞实习,这期间内推阿里,做第三次尝试. 一面: 自我介绍, ...
- vivo2020届春季校园招聘在线编程考试 [编程题]vivo智能手机产能 C++实现
[编程题]vivo智能手机产能 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 256M,其他语言512M 在vivo产线上,每位职工随着对手机加工流程认识的熟悉和经验的增加,日产量也 ...
- vivo2020届春季校园招聘在线编程考试 [编程题]数位之积 C++实现
[编程题]数位之积 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 256M,其他语言512M 现给定任意正整数 n,请寻找并输出最小的正整数 m(m>9),使得 m 的各位(个 ...
- 2014年阿里巴巴校园招聘两道算法题
昨天阿里巴巴校园招聘在线测试,总的来说算法题比较简单,至于前面的选择题不是本人的强项,个人感觉比较难.下面我们说说两道算法题: 第一题大意是有一个quary和text要求找出两者匹配最长的字符串的长度 ...
- 阿里巴巴2008校园招聘在线宣讲会
活动主题:阿里巴巴2008校园招聘在线宣讲会 活动时间: 2007年10月18日 18:30 - 20:30 主持人: 主持人 嘉宾: 阿里巴巴B2B技术部副总裁 李昂 阿里巴巴成立于1999年 ...
- 牛客网 vivo2020届春季校园招聘在线编程考试 第3题
牛客网 vivo2020届春季校园招聘在线编程考试 第3题 1.问题分析 2.问题解决 3.总结 1.问题分析 主要就是两个数学公式.代码我已经进行了详细的注释,理解应该没有问题,读者可以作为参考 ...
- 牛客网 vivo2020届春季校园招聘在线编程考试 第2题
牛客网 vivo2020届春季校园招聘在线编程考试 第2题 1.问题分析 2.问题解决 3.总结 1.问题分析 基本思路是: 1.如果有因子大于等于 10 ,说明不存在 m,使得 m 的各位(个位.十 ...
最新文章
- Android中后台定时任务实现,即时数据同步问题思考!
- python3.6 - threading 多线程编程进阶,线程间并发控制(2)
- 矩阵是怎样变换向量的
- 检查IP的shell
- 我是程序员,每一天都太难了!
- 名校教授:把研究生扔到河里,游过去的就成为博士
- 中国互联网企业综合实力研究报告(2020)
- JavaScript玩转机器学习:Node 中的 TensorFlow.js
- c++ windows forms 使用_从头开始了解和使用Hypervisor(第1部分)
- Android-----使用Button特效selector+shape
- CentOS+Apache+Mysql+Php安装及优化配置小记
- SSH项目搭建-03-DAO层,Controller层创建及代码抽取
- electron 使用 node-ffi 调用 C++ 动态链接库(DLL)
- 快递100手机端页面抓取所有快递公司名称和代码
- vue中使用echarts地图
- reflections歌词翻译_英文歌曲reflection的歌词翻译
- Modem analyze by T32 tool.
- Eclipse配色学习
- 2020 中国独立开发者生存现状调研报告
- file html5 样式,CSS小技巧之自定义个性的file表单样式
热门文章
- 基于时空注意力的图卷积网络在路段级交通预测中的应用
- STA series --- 3.Standard cell library(PART-I)
- 树莓派开机启动python脚本的另一种方法
- 来吧 兄弟萌 我们一起学做粥
- 2020携程java面试题整理,开发实习一面面经
- 苹果app退款_苹果上最流氓的功能,终于被彻底关掉,还退款208元
- InnoDB引擎--事务持久性
- SharpDevelop源码分析之插件
- advised by org.springframework.transaction.interceptor.TransactionInterceptor.invoke.........
- 了解车辆驾驶行为、成功验证C-V2X技术