软件工程师面试宝典及考题分析.docxVIP

  • 0
  • 0
  • 约7.94千字
  • 约 23页
  • 2026-11-03 发布于福建
  • 举报

第PAGE页共NUMPAGES页

2026年软件工程师面试宝典及考题分析

一、编程语言与基础算法(共5题,每题8分,总分40分)

题目1(Java基础)

编写一段Java代码,实现一个函数`intfindMax(int[]arr)`,输入一个整数数组`arr`,返回数组中的最大值。如果数组为空,返回`-1`。要求:

1.不能使用`Collections.max()`等现成方法。

2.代码需包含异常处理(例如数组为空时)。

答案与解析

java

publicclassMaxFinder{

publicstaticintfindMax(int[]arr){

if(arr==null||arr.length==0){

thrownewIllegalArgumentException(数组不能为空);

}

intmax=arr[0];

for(intnum:arr){

if(nummax){

max=num;

}

}

returnmax;

}

//测试用例

publicstaticvoidmain(String[]args){

int[]test1={3,1,4,1,5};

System.out.println(findMax(test1));//输出5

int[]tes

文档评论(0)

1亿VIP精品文档

相关文档