import java. awt. * ;
import java. awt. event. * ;
import java. time. * ;
import javax. swing. * ;
public class test {
public static void main ( String [ ] args)
{
var clock = new TalkingClock ( ) ;
clock. start ( 1000 , true ) ;
JOptionPane . showConfirmDialog ( null , "Quit program?" ) ;
System . exit ( 0 ) ;
}
}
class TalkingClock {
public void start ( int interval, boolean beep)
{
var listener = new ActionListener ( ) {
public void actionPerformed ( ActionEvent event)
{
System . out. println ( "At the tone,the time is " + Instant . ofEpochMilli ( event. getWhen ( ) ) ) ;
if ( beep) Toolkit . getDefaultToolkit ( ) . beep ( ) ;
}
} ;
var timer = new Timer ( interval, listener) ;
timer. start ( ) ;
}
}
import java. util. * ;
public class test {
public static void main ( String [ ] args)
{
var value= new double [ 20 ] ;
for ( int i= 0 ; i< value. length; i++ )
{
value[ i] = 100 * Math . random ( ) ;
}
ArrayAlg. Pair res= ArrayAlg . minmax ( value) ;
System . out. println ( res. getfirst ( ) ) ;
System . out. println ( res. getsecond ( ) ) ;
}
}
class ArrayAlg {
public static class Pair {
private double first;
private double second;
public Pair ( double f, double s)
{
first = f;
second = s;
}
public double getfirst ( )
{
return first;
}
public double getsecond ( )
{
return second;
}
}
public static Pair minmax ( double [ ] value)
{
double min= Double . POSITIVE_INFINITY;
double max= Double . NEGATIVE_INFINITY;
for ( double i: value)
{
if ( min> i) min= i;
if ( max< i) max= i;
}
return new Pair ( min, max) ;
}
}