TestComparable
public class TestCompare {
public static void main(String[] args) {
Student stu1 = new Student("tom", 18, 98);
Student stu2 = new Student("jack", 17, 99);
Student stu3 = new Student("jim", 15, 95);
Student stu4 = new Student("mike", 19, 97);
Student[] stus = {stu1, stu2, stu3, stu4};
java.util.Arrays.sort(stus);
for(int i = 0; i < stus.length; i++){
System.out.println(stus[i].name + "\t" + stus[i].age + "\t" + stus[i].score);
}
}
}
class Student implements Comparable<Student>{
String name;
int age;
double score;
public Student(String name, int age, double score) {
super();
this.name = name;
this.age = age;
this.score = score;
}
@Override
public int compareTo(Student o) {
if(this.score > o.score){
return 1;
}else if(this.score < o.score){
return -1;
}
return 0;
}
}
Goldbuch
import java.util.Scanner;
public class TestT11 {
public static void main(String[] args) {
Check a = new Check();
Scanner input = new Scanner(System.in);
Split.split(input, a);
}
}
interface MathTool{
boolean isPrime(int numi);
}
class Check implements MathTool{
@Override
public boolean isPrime(int numi) {
for(int i = 2; i < numi; i++){
if(numi % i == 0){
return false;
}
}
return true;
}
}
class Split{
public static void split(Scanner input, MathTool a ){
System.out.println("请输入一个大于6的偶数");
int num = input.nextInt();
double start = System.currentTimeMillis();
if(num > 6 && num % 2 == 0){
for(int i = 2; i < num; i++){
if(a.isPrime(i) && a.isPrime(num-i)){
System.out.println(num + "=" + i + "+" + (num - i));
System.out.println(System.currentTimeMillis() - start);
return;
}
}
}
System.out.println(System.currentTimeMillis() - start);
System.out.println("输入有误");
}
}