JAVA第9次作业
1.
public class Hestia1 {
public static void main(String[] args) {
System.out.println("请输入一个整数:");
Scanner sc = new Scanner(System.in);
int a=sc.nextInt();
if(ss(a)==true){
System.out.println(a+"是素数");
}else{
System.out.println(a+"不是素数");
}
}
public static boolean ss(int a){
for(int i=2;i<a;i++){
if(a%i==0){
return false;
}
}
return true;
}
}
2.
public class Student {
private String name;
private String stuId;
private String department;
private int score;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getStuId() {
return stuId;
}
public void setStuId(String stuId) {
this.stuId = stuId;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
public Student(String name, String stuId, String department, int score) {
this.name = name;
this.stuId = stuId;
this.department = department;
this.score = score;
}
public Student() {}
public String toString() {
return this.name+","+this.stuId+","+this.department+","+this.score;
}
public boolean equals(Student s) {
if(this.score>s.score){
return true;
}
return false;
}
}
3.
public class StudentTest {
public static void main(String[] args){
Student s1=new Student("Hestia","001","数信系",90);
Student s2=new Student("Arona","002","数信系",85);
max(s1,s2);
}
public static void max(Student s1,Student s2){
if(s1.equals(s2)){
System.out.println("成绩较好的是:");
System.out.println(s1.toString());
}else{
System.out.println("成绩较好的是:");
System.out.println(s2.toString());
}
}
}