#千锋逆战班,作业2.27#

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;

/**
 * @author Administrator
 *
 */
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("输入有误");
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值