选择就不发了自己看着写吧
ps::自己理解的仅供参考
二、简答题
Java的运行机制是什么?
java语言是一种特殊的高级语言,它既具有解释型语言的特征,也具有编译型语言的特征,因为Java程序要经过先编译,后解释两个步骤。
\2) 变量和常量有什么区别?请分别写出声明语法
变量指的是在程序运行的过程中存储可以变化的数据 int age = 18;
常量指的是在程序运行期间不变的数据 static final double p = 3.1415926
\3) 以int为例,写出变量的四种声明方式(1.先声明,后赋值 2.声明并赋值 3.先声明多个,后赋值 4.声明多个并赋值)
int a; a=0;
int a = 0;
int a; int b; a=b=0;
int a=0,b=0;
\4) &和&&有什么区别?
& 必须两侧的都是true,结果为真
&& 如果第一个表达式为false,则不再计算第二个表达式
\5) break和continue有什么作用?
break 是结束程序运行
continue 是跳过本次循环,进入下一次循环
\6) 一维数组有几种创建方式,请至少写出两种(int)
int[] arr= {1,2,3};
int[] arr= new int[1,2,3,4];
\7) this关键字和super关键字有什么区别?
this 当前对象的引用
super 父类空间的引用
\8) Java面向对象的三大特点是什么?
继承,封装,多态
\9) 什么是继承?
子类拥有父类所有的属性,继承是类和类之间的一种关系
\10) 请简述你对多态的理解
同一个对象,在不同时刻体现出来的不同状态,多态的关键是每个子类都要重写方法,实现了继承了同样的方法名称但是又有每个的特点,就像龙生九子,每个不一样,有两个好处,一个是类关系清晰,另一个是方法调用方便,只要有传入实参就行。
## 三、编程题
1) 打印九九乘法表
public class jiujiu {
public static void main(String[] args) {
for (int i = 1; i < 10; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(j + "×" + i + "=" + i*j +"\t");
}
System.out.println();
}
}
}
2. 数组{1,3,5,7}和{2,4,6,8},要求合并数组,并升序排列
public class shuzu {
public static void main(String[] args) {
int[] a={1,3,5,7};
int[] b={2,4,6,8};
int[] c = new int[a.length+b.length];
for (int i = 0; i <a.length ; i++) {
c[i] = a[i];
}
for (int i = a.length, j = 0; i < a.length+b.length ; i++,j++) {
c[i] = b[j];
}
ArrayList arr = new ArrayList();
for (int i = 0; i <c.length ; i++) {
arr.add(c[i]);
}
Collections.sort(arr);
System.out.println(arr);
}
}
3. 编写一个猜数字的游戏1-100(程序运行一次,猜错继续,猜中结束-递归/循环)
public class there {
public static void main(String[] args) {
int a = (int)Math.round(Math.random()*(100-1)+1);
while (true){
Scanner sc = new Scanner(System.in);
System.out.println("猜一个1~100之间的数");
int b = sc.nextInt();
if(b == a){
System.out.println("猜对结束!!!!");
break;
}else{
System.out.println("你猜错了,继续吧");
}
}
}
}
4.编写程序,模拟饲养员喂动物,体现多态
public abstract class Animal {
private String name;
public abstract void eat();
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
public class Dog extends Animal{
public void eat() {
System.out.println(super.getName() + "啃骨头");
}
}
public class Cat extends Animal{
public void eat() {
System.out.println(super.getName() + "吃鱼");
}
}
public class Feeder {
private String name; //姓名
public void feed(Dog dog){
System.out.println(this.name+"喂"+dog.getName());
dog.eat();
}
public void feed(Cat cat){
System.out.println(this.name+"喂"+cat.getName());
cat.eat();
}
public void feed(Animal animal){
System.out.println(this.name+"喂"+animal.getName());
animal.eat();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
public class Test {
public static void main(String[] args) {
Dog dog = new Dog();
dog.setName("志辉");
Cat cat = new Cat();
cat.setName("智慧");
//创建一个饲养员对象
Feeder feeder = new Feeder();
feeder.setName("小孙");
//饲养动物
feeder.feed(dog);
feeder.feed(cat);
}
}
## 四、智力题
有一个瓶子,一开始放进去一个虫子,虫子每过2秒分裂,一分为二,过两分钟后装满瓶子,如果一开始放进去两个虫子,请问多长时间装满虫子?
这个怎么说吧118秒,直接看出来好吧,
1 2 4 8
2 4 8 16 够明星了吧