T1
import java. util. Date;
public class T1 {
public static void main ( String[ ] args) {
long l= 10000 ;
for ( int i= 0 ; i< 8 ; i++ ) {
Date d = new Date ( ) ;
d. setTime ( l) ;
System. out. println ( d) ;
l*= 10 ;
}
}
}
T2
import java. util. Random;
public class T2 {
public static void main ( String[ ] args) {
Random rand = new Random ( 1000 ) ;
for ( int i= 0 ; i< 50 ; i++ )
System. out. println ( rand. nextInt ( 100 ) ) ;
}
}
T3
import java. util. GregorianCalendar;
public class T3 {
public static void main ( String[ ] args) {
java. util. GregorianCalendar date= new java. util. GregorianCalendar ( ) ;
System. out. println ( date. get ( GregorianCalendar. YEAR) + "年" +
( 1 + date. get ( GregorianCalendar. MONTH) ) + "月" +
date. get ( GregorianCalendar. DAY_OF_MONTH) + "日"
) ;
java. util. GregorianCalendar d = new java. util. GregorianCalendar ( ) ;
long a = 1234567898765 L;
d. setTimeInMillis ( a) ;
System. out. println ( d. get ( GregorianCalendar. YEAR) + "年" +
( 1 + d. get ( GregorianCalendar. MONTH) ) + "月" +
d. get ( GregorianCalendar. DAY_OF_MONTH) + "日"
) ;
}
}
T4
public class T4 {
public static void main ( String[ ] args) {
StopWatch m = new StopWatch ( ) ;
m. start ( ) ;
for ( int i = 0 ; i < 9999999 ; i++ ) {
for ( int j = 0 ; j < 9999999 ; j++ ) {
}
}
m. stop ( ) ;
System. out. println ( m. getElapsedTime ( ) ) ;
}
}
class StopWatch {
private long startTime;
private long endTime;
public long getStartTime ( ) {
return startTime;
}
public long getEndTime ( ) {
return endTime;
}
public StopWatch ( ) {
this . startTime = System. currentTimeMillis ( ) ;
}
public void start ( ) {
this . startTime = System. currentTimeMillis ( ) ;
}
public void stop ( ) {
this . endTime = System. currentTimeMillis ( ) ;
}
public long getElapsedTime ( ) {
return this . endTime - this . startTime;
}
}
T5
import java. util. Scanner;
public class T5 {
public static void main ( String[ ] args) {
Scanner input= new Scanner ( System. in) ;
int a= input. nextInt ( ) ;
int b= input. nextInt ( ) ;
int c= input. nextInt ( ) ;
QuadraticEquation p = new QuadraticEquation ( a, b, c) ;
int q= p. getDiscriminant ( ) ;
System. out. print ( "judge:" ) ;
System. out. println ( q) ;
if ( q> 0 ) {
System. out. print ( "root1:" ) ;
System. out. println ( p. getRoot1 ( ) ) ;
System. out. print ( "root2:" ) ;
System. out. println ( p. getRoot2 ( ) ) ;
}
else if ( q== 0 ) {
System. out. print ( "root:" ) ;
System. out. println ( p. getRoot1 ( ) ) ;
}
else {
System. out. println ( "The equation has no roots." ) ;
}
}
}
class QuadraticEquation {
private int a;
private int b;
private int c;
public int getA ( ) {
return a;
}
public int getB ( ) {
return b;
}
public int getC ( ) {
return c;
}
public QuadraticEquation ( int a, int b, int c) {
this . a= a;
this . b= b;
this . c= c;
}
public int getDiscriminant ( ) {
if ( b* b- 4 * a* c> 0 )
return 1 ;
else if ( b* b- 4 * a* c== 0 )
return 0 ;
else
return - 1 ;
}
public double getRoot1 ( ) {
return ( - b+ Math. sqrt ( b* b- 4 * a* c) ) / ( 2 * a) ;
}
public double getRoot2 ( ) {
return ( - b- Math. sqrt ( b* b- 4 * a* c) ) / ( 2 * a) ;
}
}
T6
在这里插入代码片import java. util. Scanner;
public class T6 {
public static void main ( String[ ] args) {
Scanner input = new Scanner ( System. in) ;
double a= input. nextDouble ( ) ;
double b= input. nextDouble ( ) ;
double c= input. nextDouble ( ) ;
double d= input. nextDouble ( ) ;
double e= input. nextDouble ( ) ;
double f= input. nextDouble ( ) ;
LinearEquation p = new LinearEquation ( a, b, c, d, e, f) ;
if ( p. isSolvable ( ) == true ) {
System. out. print ( "x:" ) ;
System. out. println ( p. getX ( ) ) ;
System. out. print ( "y:" ) ;
System. out. println ( p. getY ( ) ) ;
}
else {
System. out. println ( "The equation has no solution." ) ;
}
}
}
class LinearEquation {
private double a;
private double b;
private double c;
private double d;
private double e;
private double f;
public LinearEquation ( double a, double b, double c, double d, double e, double f) {
this . a= a;
this . b= b;
this . c= c;
this . d= d;
this . e= e;
this . f= f;
}
public double getA ( ) {
return a;
}
public double getB ( ) {
return b;
}
public double getC ( ) {
return c;
}
public double getD ( ) {
return d;
}
public double getE ( ) {
return e;
}
public double getF ( ) {
return f;
}
public boolean isSolvable ( ) {
if ( a* d- b* c!= 0 ) {
return true ;
}
else
return false ;
}
public double getX ( ) {
return ( e* d- b* f) / ( a* d- b* c) ;
}
public double getY ( ) {
return ( a* f- e* c) / ( a* d- b* c) ;
}
}