面试必备100道经典Java基础题Word格式文档下载.docx

上传人:b****1 文档编号:4293207 上传时间:2023-05-03 格式:DOCX 页数:127 大小:55.58KB
下载 相关 举报
面试必备100道经典Java基础题Word格式文档下载.docx_第1页
第1页 / 共127页
面试必备100道经典Java基础题Word格式文档下载.docx_第2页
第2页 / 共127页
面试必备100道经典Java基础题Word格式文档下载.docx_第3页
第3页 / 共127页
面试必备100道经典Java基础题Word格式文档下载.docx_第4页
第4页 / 共127页
面试必备100道经典Java基础题Word格式文档下载.docx_第5页
第5页 / 共127页
面试必备100道经典Java基础题Word格式文档下载.docx_第6页
第6页 / 共127页
面试必备100道经典Java基础题Word格式文档下载.docx_第7页
第7页 / 共127页
面试必备100道经典Java基础题Word格式文档下载.docx_第8页
第8页 / 共127页
面试必备100道经典Java基础题Word格式文档下载.docx_第9页
第9页 / 共127页
面试必备100道经典Java基础题Word格式文档下载.docx_第10页
第10页 / 共127页
面试必备100道经典Java基础题Word格式文档下载.docx_第11页
第11页 / 共127页
面试必备100道经典Java基础题Word格式文档下载.docx_第12页
第12页 / 共127页
面试必备100道经典Java基础题Word格式文档下载.docx_第13页
第13页 / 共127页
面试必备100道经典Java基础题Word格式文档下载.docx_第14页
第14页 / 共127页
面试必备100道经典Java基础题Word格式文档下载.docx_第15页
第15页 / 共127页
面试必备100道经典Java基础题Word格式文档下载.docx_第16页
第16页 / 共127页
面试必备100道经典Java基础题Word格式文档下载.docx_第17页
第17页 / 共127页
面试必备100道经典Java基础题Word格式文档下载.docx_第18页
第18页 / 共127页
面试必备100道经典Java基础题Word格式文档下载.docx_第19页
第19页 / 共127页
面试必备100道经典Java基础题Word格式文档下载.docx_第20页
第20页 / 共127页
亲,该文档总共127页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

面试必备100道经典Java基础题Word格式文档下载.docx

《面试必备100道经典Java基础题Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《面试必备100道经典Java基础题Word格式文档下载.docx(127页珍藏版)》请在冰点文库上搜索。

面试必备100道经典Java基础题Word格式文档下载.docx

staticvoidsort(int[]a,intlow,inthigh){

if(low>

=high)return;

//low小于high,则直接返回

if((high-low)==1){//如果只有两个数字,则直接比较

if(a[0]>

a[1])

s);

return;

intpivot=a[low];

//取第一个数作为中间数

intleft=low+1;

intright=high;

while(left<

right){

//从左边开始找

while(left<

right&

&

left<

=high){//如果左小于右则一直循环

if(a[left]>

pivot)break;

left++;

//左下标往右边走一点

//从右边开始找

=right&

right>

low){//如果左大于右则一直循环

if(a[right]<

=pivot)

break;

right--;

//右下标往左走一点

if(left<

right)//如果还没有找完,则交换数字

sort(a,low,right);

sort(a,right+1,high);

//调位方法

privatestaticvoids[]array,inti,intj){

inttemp;

temp=array[i];

array[i]=array[j];

array[j]=temp;

}

打印结果为:

1004060873411560

0113440566087100

冒泡排序

publicclassTest002{

int[]arr={100,40,60,87,34,11,56,0};

//定义数组

maopaoPrint(arr);

maopaoSort(arr);

publicstaticvoidmaopaoSort(int[]arrys){

//定义临时变量temp

inttemp=0;

//用j表示下标,遍历数组

for(intj=0;

j<

arrys.length;

j++){

//对于每一个数组元素,从0到还未排序的最大下标,总是把最大的数字放在后边

for(intk=0;

k<

arrys.length-j-1;

k++){

if(arrys[k]>

arrys[k+1]){//判断当前数字与后面数字的大小

temp=arrys[k];

arrys[k]=arrys[k+1];

arrys[k+1]=temp;

maopaoPrint(arrys);

//打印输出

publicstaticvoidmaopaoPrint(int[]l){

l.length;

System.out.print(l[i]+"

//从小到大的输出

0113440566087100

2.采用折半查找的算法,在数组中查询到某个数;

importjava.util.Scanner;

publicclassTest003{

publicstaticintMax=20;

//数据数组源

publicstaticintdata[]={12,16,19,22,25,32,39,39,48,55,57,58,

63,68,69,70,78,84,88,90,97};

//计数器

publicstaticintcount=1;

请输入您要查找的数字:

Scannersc=newScanner(System.in);

intKeyValue=sc.nextInt();

//调用折半查找

if(Search(KeyValue)){

//输出查找次数

共查找了"

+count+"

次"

}else{

//输出没有找到数据

抱歉,数据数组源中找不到您输入的数字"

//折半查找法

publicstaticbooleanSearch(intk){

intleft=0;

//左边界变量

intright=Max-1;

//右边界变量

intmiddle;

//中位数变量

while(left<

=right){

middle=(left+right)/2;

if(k<

data[middle]){

right=middle-1;

//查找前半段

}elseif(k>

left=middle+1;

//查找后半段

}elseif(k==data[middle]){

Data["

+middle+"

]="

+data[middle]);

returntrue;

count++;

returnfalse;

3.输入一个字符串,其中包含数字、特殊符号(像:

¥、&

、(、>

等)、大小写字母等,然后输出每个字符串或符号的ASCII码的和;

例如:

输入“@#$%^&

*():

|”,则打印出643。

请输入一个字符串:

Stringstr=sc.nextLine();

intsum=0;

str.length();

sum=sum+str.charAt(i);

您输入的字符串每个字节相加的和为:

+sum);

4.将一个数组中值=0的项去掉,将不为0的值存入一个新的数组

比如:

inta[]={0,1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5};

生成的新数组为:

intb[]={1,3,4,5,6,6,5,4,7,6,7,5}

importjava.util.*;

inta[]={0,1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5};

List<

Integer>

list=newArrayList<

();

for(inti=0;

i<

a.length;

i++){

if(a[i]!

=0){

list.add(a[i]);

intb[]=newint[list.size()];

for(inti=0;

list.size();

b[i]=list.get(i);

原数组为:

System.out.print(a[i]+"

去掉值为0的项之后为:

for(inti:

b){

System.out.print(i+"

5.定义10个长度的Student数组,将10个Student对象的年龄全部加1,然后把10个Student对象的详细信息逐行打印出来(数组和ArrayList实现)

第一个类:

publicclassStudent{

publicStringname;

publicStringsex;

publicintage;

publicStringgetName(){

returnname;

publicvoidsetName(Stringname){

this.name=name;

publicStringgetSex(){

returnsex;

publicvoidsetSex(Stringsex){

this.sex=sex;

publicintgetAge(){

returnage;

publicvoidsetAge(intage){

this.age=age;

publicStudent(Stringname,Stringsex,intage){

super();

第二个类:

importjava.util.ArrayList;

importjava.util.List;

staticStudent[]s=newStudent[10];

intk=1;

Student>

li=newArrayList<

10;

li.add(newStudent("

zhangsan"

+i,"

男"

20));

(li.get(i).age)++;

System.out.println(li.get(i).getName()+"

+li.get(i).getSex()+"

+li.get(i).getAge());

6.有工人,农民,教师,科学家,服务生,其中,工人,农民,服务生只有基本工资.教师除基本工资外,还有课酬(元/天),科学家除基本工资外,还有年终奖,请你写出相关类,将各种类型的员工的全年工资打印出来

(共有7个类)

packagecom.softeem.zy006;

/**

*定义一个人的接口,以供实现

*/

publicinterfacePeople{

publicdoublenum();

*工人类

publicclassWorkerimplementsPeople{

privatedoublemontherSalary;

publicWorker(doublemontherSalary){

this.montherSalary=montherSalary;

publicdoublenum(){

returngetMontherSalary()*12;

publicdoublegetMontherSalary(){

returnmontherSalary;

publicvoidsetMontherSalary(doublemontherSalary){

第三个类:

*农民类

publicclassPeasantimplementsPeople{

publicPeasant(doublemontherSalary){

第四个类:

*教师类

publicclassTeacherimplementsPeople{

privatedoubledaySalary;

publicTeacher(doublemontherSalary,doubledaySalary){

this.daySalary=daySalary;

returngetMontherSalary()*12+getDaySalary()*365;

publicdoublegetDaySalary(){

returndaySalary;

publicvoidsetDaySalary(doubledaySalary){

第五个类:

*科学家类

publicclassScientistimplementsPeople{

privatedoubleprojectSalary;

publicScientist(doublemontherSalary,doubleprojectSalary){

this.projectSalary=projectSalary;

publicdoublenum(){

returngetMontherSalary()*12+getProjectSalary();

publicdoublegetProjectSalary(){

returnprojectSalary;

publicvoidsetProjectSalary(doubleprojectSalary){

第六个类:

*服务员类

publicclassWaiterimplementsPeople{

publicWaiter(doublemontherSalary){

publicvoid

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 初中教育 > 语文

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2