栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

java期末复习题目

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

java期末复习题目

小题
  1. 字符串长度方法 length()

  2. Math.floor(3.4) //3.0 向下取整

  3. Math.ceil(3.4) //4.0 向上取整

  4. 2>8&&9<2 //false 两边都是false

  5. 实现接口的关键字是 implements

  6. String str = “hello”

    str.subtring(1,2) //输出e 从0数 1-2(不取到2)

  7. 三大特性 //封装 继承 多态

  8. -5%3 // -2

  9. try…catch //try包裹可能出错的内容 catch包裹报错后执行的内容

  10. int a=2 a+=3 //a=5

  11. 随机数函数 //random

判断题
  1. if语句中的条件表达式的值可以是int型数据(×)
  2. 在switch语句中的条件表达式必须要有default选项(×)
  3. 声明变量时必须指定一个类型(✓)
  4. 构造方法是类的一种特殊函数,它的方法名必须与类名相同(✓)
  5. java语言中允许一个类实现多个接口(✓)
  6. abstract类的子类必须是非抽象类(×)
  7. final类可以有子类(×)
  8. 不允许同时final和abstract修饰同一个方法(✓)
  9. string类是final类不可以有子类(✓)
  10. 允许接口中只有一个抽象方法(✓)
  11. 源文件中public类可以有0个或多个(✓)
  12. java语言中允许一个类继承多个类(错)
  13. 构造方法一般在创新对象时,系统会自动调用(✓)
  14. 可以同时用final和abstract修饰同一个方法(×)
  15. java中局部变量没有默认值(✓)
  16. 接口中的常量可以不指定初值(×)
  17. 不存在继承关系的情况下也可以实现重写(×)
  18. 可以在接口中只声明变量不定义方法(✓)
  19. 类中static修饰变量式方法可以用类名或对像访问(✓)
  20. 字符串ABC===ABC的值是true(✓)
阅读题 阅读程序-1
  • x:-5
  • y:-1
	public static void main(String[] args) {
        int x = 1,y = 6;
        while (y-->0){
            x--;
        }
        System.out.println("x:"+x+"y:"+y);
     }
阅读程序-2
  • 输出-100
class D{
   int x=100,y=200;
    public void setX(int x) {
        x = x;
    }
    public void setY(int y) {
        this.y = y;
    }

    public int getXYsum() {
        return x+y;
    }
}
public class cy {
    public static void main(String[] args) {
      D d = new D();
      d.setX(-100);
      d.setY(-200);
      System.out.println(d.getXYsum());
    }
}
阅读程序-3
  • 输出 11 和 110
class A{
    public int getNumber(int a) {
        return a+1;
    }
}
class B extends A{
    public int getNumber(int a) {
        return a+100;
    }
}
public class cy {
    public static void main(String[] args) {
        A a = new A();
        System.out.println(a.getNumber(10)); //
        a = new B();
        System.out.println(a.getNumber(10));//
    }
}
程序题 十以内的阶乘之和
	public static void main(String[] args) {
        int sum=0;
        int a = 1;
        for (int i = 1;i<=10;i++){
           a=a*i;
           sum = sum+a;
        }
    	System.out.println(sum);
     }
求累加一万以内最大整数
    public static void main(String[] args) {
        int sum = 0;
        int flg=0;
        for (int i = 1; i < 10000; i++) {
            sum += i;
            if (sum < 10000) {
                flg=i;
            } else {
                System.out.println("最大正整数:" + flg);//140
                break;
            }
        }
    }
方法的考察–1
  • 类名retong,宽高double类型默认是1
  1. 无参构造方法
  2. 给定宽高的构造方法
  3. getmj 返回面积的方法
  4. getzc 返回周长的方法
class retong{
    double witdh = 1;
    double height = 1;
    retong(){
        System.out.println("无参构造方法");
    }
    retong(double w,double h){
        this.witdh = w;
        this.height = h;
        System.out.println("有参构造方法");
    }
    double getmj(){
        return witdh*height;
    }
    double getzc(){
        return witdh*2+height*2;
    }
}
public class cy {
    public static void main(String[] args) {
    	
        retong a = new retong(2,4); //给定宽高
        System.out.println(a.getmj());
        System.out.println(a.getzc());
    }
}
方法的考察–2
  • 类名radius,宽高double类型
  1. 无参构造方法
  2. 定义一个 static PI (静态)
  3. 给定半径的构造方法
  4. getmj 返回面积的方法
  5. getzc 返回周长的方法
class radius{
    double radius;
    static double PI = 3.14;
    radius(){
        System.out.println("无参构造方法");
    }
    radius(double r){
        this.radius = r;
        System.out.println("指定半径的有参构造方法");
    }
    double getmj(){
        return PI*radius*radius;
    }
    double getzc(){
        return PI*(2*radius);
    }
}
public class cy {
    public static void main(String[] args) {
    	
        radius a = new radius(13); //给定半径
        System.out.println(a.getmj());
        System.out.println(a.getzc());
    }
}
需要注意的知识点

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/959610.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号