java求e代码 java代码示例( 二 )


Collections.sort( studentBir, (o1, o2) - ( o1.getBirthDay().compareTo( o2.getBirthDay() ) ) );
studentBir.forEach( stu -{
System.out.println( stu.getName() + " | " + getTime(stu.getBirthDay()) + " | " + stu.getMark() );
} );
System.out.println(" ②第二种排序,按照成绩降序;");
ListStudent markDesc = students.stream().sorted((a, b) - b.getMark() - a.getMark()).collect(Collectors.toList());
markDesc.forEach( stu -{
System.out.println( stu.getName() + " | " + getTime(stu.getBirthDay()) + " | " + stu.getMark() );
} );
System.out.println("③比较输出:计算他们互相大多少天,要考虑到闰年 。");
for ( int i = 0 ; istudents.size() ; i++ ){
for ( int j = i + 1 ; jstudents.size() ; j++ ){
Long ageSub = students.get( i ).getBirthDay().getTime() - students.get( j ).getBirthDay().getTime();
Long dateSub = ageSub/(1000*60*60*24);
if ( dateSub0 ){
System.out.println( students.get( i ).getName() + "比" + students.get( j ).getName() + "大" + dateSub );
}else if ( dateSub0 ){
System.out.println( students.get( i ).getName() + "比" + students.get( j ).getName() + "小" + -dateSub );
}else {
System.out.println( students.get( i ).getName() + "和" + students.get( j ).getName() + "同日出生");
}
}
}
}
public static void markBeyong( int mark ,int targetMark){
double markDou = mark;
double targetMarkDou = targetMark;
boolean b = true;
int month = 0;
while ( b ){
if ( markDoutargetMarkDou ){
markDou = markDou*1.02;
month ++;
}else {
System.out.println("一共用了" + month + "个月反超");
b = false;
}
}
}
public static Date getTime( String target ) {
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd");
Date date = sdf.parse(target);
return date;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
public static String getTime( Date target ) {
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd");
String date = sdf.format( target );
return date;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
}
class Student {
private String name;
private Date birthDay;
private Integer mark;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Date getBirthDay() {
return birthDay;
}
public void setBirthDay(Date birthDay) {
this.birthDay = birthDay;
}
public Integer getMark() {
return mark;
}
public void setMark(Integer mark) {
this.mark = mark;
}
public Student(){
}
public Student(String name,Date birthDay , Integer mark){
this.name = name;
this.birthDay = birthDay;
this.mark = mark;
}
}
java随机分配!比如有五个座位a, b, c ,d ,e , 有五个学生1,2,3,4,5 把学生分配到座位上不能有重复!求代码import java.util.*;
public class a {
public static void main(String[] args) {
int i;
char c;
String[] a = {"座位1","座位2","座位3","座位4","座位5"};
/*生成座位list*/
ListString seat = new ArrayListString();
/*向其中添加座位*/
for(i = 0;i5;i++){
seat.add(a[i]);
}
/*调用函数,将顺序打乱*/
Collections.shuffle(seat);
/*显示结果*/
for(i = 0,c = 'a'; c = 'e';c++,i++){
System.out.println("学生"+c+"坐在"+seat.get(i));
}
}
}
有问题追问我
用java.EE编写计算器程序代码java EE是java企业级开发平台的意思,实在是看不出跟计算器这种小程序有什么关联 。不知道楼主要找的是不是这个 。

推荐阅读