Java——阶段练习(4)

简介: 代码如下

第二阶段考核题

1

package studio.hyk.hyk.text1;
public class text1 {
    public static void main(String[] args) {
        double a=2,b=1;
        double f=1;
        double c=0;
        double  e;
        for(int d=1;d<=20;d++){
            e=a/b;
            c+=e;
            f=b;
            b=a;
            a=a+f;
        }
        System.out.println(c);
    }
}

2

mport  java.util.*;
import java.util.Arrays;
public class text2 {
    public static void main(String[] args) {
        int c;
        int e=0;
        Scanner r=new Scanner(System.in);
        String b=r.nextLine();
        char []a=new char[b.length()-1];
        a=b.toCharArray();
        for (c=0;c<=(b.length()-1)/2;c++){
        if(a[c]!=a[b.length()-1-c]){
               e++;
           }
        }
        if(e==0){
            System.out.println("该字符串回文");
        }
        else{
            System.out.println("该字符串不回文");
        }
    }
}

3

package studio.hyk.hyk.text3;
import java.util.*;
interface Library{
   public abstract void  borrow();
   public abstract void revert();
}
class Book{
    String name;
    String publisher;
    public Book(){};
    public Book(String name,String publisher){
        this.name=name;
        this.publisher=publisher;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Book)) return false;
        Book book = (Book) o;
        if (!name.equals(book.name)) return false;
        return publisher.equals(book.publisher);
    }
    @Override
    public int hashCode() {
        int result = name.hashCode();
        result = 31 * result + publisher.hashCode();
        return result;
    }
    public String toString (){
        return "书名;"+name+"."+"出版社;"+publisher;
    }
}
class CollectionBook extends Book implements Library{
    String bNo;
    String stacks;
    boolean isBorrow;
    public CollectionBook(String a,String b,String c,String d){
        super(c,d);
        bNo=a;
        stacks=b;
    }
    public void borrow(){
        int x;
        Scanner r=new Scanner(System.in);
        x=r.nextInt();
        if (x>=0&&this.isBorrow==false){
            System.out.println("借阅成功");
            isBorrow=true;
        }
        else{
            System.out.println("对不起,图书已借阅");
        }
    }
    public void revert() {
        int y;
        Scanner r=new Scanner(System.in);
        y=r.nextInt();
        if(y>=0&&isBorrow==true){
            System.out.println("归还成功");
        }
        else{
            System.out.println("该图书已归还");
        }
    }
}
public class text3 {
    public static void main(String[] args) {
        CollectionBook book1=new CollectionBook("001","教学类","java编程","人民出版社");
        CollectionBook book2=new  CollectionBook("002","阅读类","java阅读","清华出版社");
        System.out.println(book1.equals(book2));
        book1.isBorrow=false;
        book1.borrow();
        book1.revert();
    }
}

java25题;

class xx{
    int x;
    int y;
    public  xx(int a,int b){
        x=a;
        y=b;
    }
    @Override
    public String toString() {
        return "xx{" +
                "x=" + x +
                ", y=" + y +
                '}';
    }
}
public class xy {
    public static void main(String[] args) {
        xx yy = new xx(66, 88);
        System.out.println(yy.toString());
    }
class Professor {
    private String name;
    private String sex;
    private int age;
    private String course;
    private int result;
    public String getDetails(){
       return name+sex+age+course;
    }
    public  String  set_reslut(int x){
        if(x>0&&x<=3){
            return "可设置";
        }
        else{
            return "不可设置";
        }
    }
    public Professor(String x,String y,int z,String w){
     name=x;
     sex=y;
     age=z;
     course=w;
    }
}
public class 第21 {
    public static void main(String[] args) {
        Professor p=new Professor("那纳米","女",16,"日语");
        System.out.println(p.set_reslut(2));
    }
}
abstract class nb{
    static float pi=3.14159F;
    abstract float volume(double r);
    abstract float area(double r);
}
class sb extends nb{
    public float volume(double r){
        return (float) ((4*pi*r*r*r)/3);
    }
     public float area(double r){
        return (float) ( pi*r*r);
     }
}
public class 第22 {
    public static void main(String[] args) {
        sb jj=new sb();
        System.out.println("体积为;"+jj.volume(3));
        System.out.println("面积为"+jj.area(4));
    }
}
import java.util.Arrays;
import java.util.Objects;
class Person{
     String name;
     char sex;
     int age;
    public Person(){}
    public Person(String a,char b,int c){
        this.name=a;
        this.sex=b;
        this.age=c;
    }
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Person)) return false;
        Person person = (Person) o;
        return sex == person.sex &&
                age == person.age &&
                Objects.equals(name, person.name);
    }
    @Override
    public int hashCode() {
        return Objects.hash(name, sex, age);
    }
}
class Student extends Person {
    long number;
    int phi;
    int eng;
    int comp;
    double s;
    int mi;
    int ma;
    public Student (String o,char p,int q,int x,int y,int z,Long m){
        super(o,p,q);
        phi=x;
        eng=y;
        comp=z;
        number=m;
    }
    public double aver() {
        this.s=(phi+eng+comp)/3;
       return s;
    }
    public int max() {
        int aa[]={phi,eng,comp};
        Arrays.sort(aa);
       ma=aa[2];
       return ma;
    }
   public int min(){
       int aa[]={phi,eng,comp};
        Arrays.sort(aa);
        mi=aa[0];
        return mi;
    }
    public String tostring (){
        return "学号;"+number+"姓名;"+name+"性别;"+sex+"平均分;"+s+"最高分;"+ma+"最低分;"+mi;
    }
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Student)) return false;
        if (!super.equals(o)) return false;
        Student student = (Student) o;
        return number == student.number&&name ==student.name&&sex==student.sex&&age==student.age;
    }
}
public class 第18 {
    public static void main(String[] args) {
    Student stu=new Student("玛卡巴卡",'女',18,97,98,99,2020157L);
    Student dent=new Student("叮叮车",'男',19,99,96,94,2020157L);
    stu.aver();
    stu.min();
    stu.max();
    dent.aver();
    dent.min();
    dent.max();
        System.out.println(stu.tostring());
        System.out.println(stu.equals(dent));
    }
}
class A{
    String x;
    public A(){}
    public A(String a) {
      x=a;
    }
}
class B extends A{
    int x;
    public B(){}
    public B(int b,String c){
        super(c);
        this.x=b;
    }
    public void  myPrint (){
        System.out.println(super.x+this.x);
    }
}
public class 第20 {
    public static void main(String[] args) {
        B bb=new B(20,"拉拉");
        bb.myPrint();
    }
}
目录
相关文章
|
7月前
|
Java
【java】小学生数学练习题目生成系统
小学生数学练习题目生成系统
|
7月前
|
Java API
Java之File类的详细解析及小练习
2. File类 2.1 概述 java.io.File 类是文件和目录路径名的抽象表示,主要用于文件和目录的创建、查找和删除等操作。 2.2 构造方法
84 0
|
7月前
|
Java
Java之多线程的综合练习二
练习六:多线程统计并求最大值 需求: 在上一题基础上继续完成如下需求: 每次抽的过程中,不打印,抽完时一次性打印(随机)
58 0
|
5月前
|
Java
【Java】程序练习1(数组)
【Java】程序练习1(数组)
|
7月前
|
机器学习/深度学习 Java Windows
Java练习-2023-3-29
Java练习-2023-3-29
29 0
|
7月前
|
算法 Java Python
保姆级Java入门练习教程,附代码讲解,小白零基础入门必备
保姆级Java入门练习教程,附代码讲解,小白零基础入门必备
|
7月前
|
存储 搜索推荐 算法
【详识JAVA语言】数组练习
【详识JAVA语言】数组练习
52 1
|
7月前
|
机器学习/深度学习 Java
第十四届蓝桥杯集训——练习解题阶段(无序阶段)-Java全排列公式
第十四届蓝桥杯集训——练习解题阶段(无序阶段)-Java全排列公式
65 0
|
7月前
|
网络协议 Java
Java之TCP,UDP综合小练习一
4. 综合练习 练习一:多发多收 需求: 客户端:多次发送数据
48 0
|
7月前
|
Java
Java之多线程综合练习小题一
2. 多线程综合练习 练习一:售票 需求: 一共有1000张电影票,可以在两个窗口领取,假设每次领取的时间为3000毫秒,
117 0