第二阶段考核题
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(); } }