问题1
public class q1 {
public static void main ( String [ ] args) throws Exception {
Student [ ] s = new Student [ 5 ] ;
for ( int i = 0 ; i < 5 ; i++ )
s[ i] = new Student ( "小明" + i, Math . random ( ) * 100 , Math . random ( ) * 100 , Math . random ( ) * 100 ) ;
Arrays . sort ( s, ( a, b) -> ( int ) ( b. cScore + b. eScore + b. mScore - a. eScore - a. mScore - a. cScore) ) ;
FileOutputStream fos = new FileOutputStream ( "E:\\TEXT\\4.txt" ) ;
ObjectOutputStream oos = new ObjectOutputStream ( fos) ;
oos. writeObject ( s) ;
oos. close ( ) ;
fos. close ( ) ;
}
}
问题2
线程1
public class Thread01 extends Thread {
@Override
public void run ( ) {
int i = 0 ;
while ( true ) {
try {
Thread . sleep ( 1000 ) ;
} catch ( InterruptedException e) {
e. printStackTrace ( ) ;
}
System . out. println ( i++ ) ;
i = i % 101 ;
}
}
}
线程2
public class Thread02 extends Thread {
@Override
public void run ( ) {
BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in) ) ;
String s;
while ( true ) {
try {
if ( ! ! ( s= br. readLine ( ) ) . equals ( "Q" ) ) break ;
} catch ( IOException e) {
e. printStackTrace ( ) ;
}
}
}
}
main方法
public class q2 {
public static void main ( String [ ] args) {
Thread01 thread01 = new Thread01 ( ) ;
thread01. setDaemon ( true ) ;
thread01. start ( ) ;
Thread02 thread02 = new Thread02 ( ) ;
thread02. start ( ) ;
}
}