Lab Max Min
import java.io.*;
public class Max_min {
public Max_min() {
}
public static void main(String[] args)throws IOException{
System.out.println("please enter the count of a list of number\n"+" (two at least) ");
double max,min;
BufferedReader keyboard= new BufferedReader(new InputStreamReader(System.in));
String inputString = keyboard.readLine();
int next = Integer.parseInt(inputString);
System.out.println("/////////////");
BufferedReader keyboard1= new BufferedReader(new InputStreamReader(System.in));
String inputString1 = keyboard1.readLine();
double next1 = Double.parseDouble(inputString1);
BufferedReader keyboard2= new BufferedReader(new InputStreamReader(System.in));
String inputString2 = keyboard2.readLine();
double next2 = Double.parseDouble(inputString2);
int i=next;
if(next2>next1)
{max=next2;
min=next1;}
else{
max=next1;
min=next2;
}
for(i=next;i>2;i--){
BufferedReader keyboard3= new BufferedReader(new InputStreamReader(System.in));
String inputString3 = keyboard3.readLine();double next3 = Double.parseDouble(inputString3);
if((next3>next1)&&(next3>next2))
max=next3;
else if ((next3
min=next3;
}
System.out.println("max="+max);
System.out.println("min="+min);
}
}
public class Max_min {
public Max_min() {
}
public static void main(String[] args)throws IOException{
System.out.println("please enter the count of a list of number\n"+" (two at least) ");
double max,min;
BufferedReader keyboard= new BufferedReader(new InputStreamReader(System.in));
String inputString = keyboard.readLine();
int next = Integer.parseInt(inputString);
System.out.println("/////////////");
BufferedReader keyboard1= new BufferedReader(new InputStreamReader(System.in));
String inputString1 = keyboard1.readLine();
double next1 = Double.parseDouble(inputString1);
BufferedReader keyboard2= new BufferedReader(new InputStreamReader(System.in));
String inputString2 = keyboard2.readLine();
double next2 = Double.parseDouble(inputString2);
int i=next;
if(next2>next1)
{max=next2;
min=next1;}
else{
max=next1;
min=next2;
}
for(i=next;i>2;i--){
BufferedReader keyboard3= new BufferedReader(new InputStreamReader(System.in));
String inputString3 = keyboard3.readLine();double next3 = Double.parseDouble(inputString3);
if((next3>next1)&&(next3>next2))
max=next3;
else if ((next3
min=next3;
}
System.out.println("max="+max);
System.out.println("min="+min);
}
}
0 Comments:
張貼留言
<< Home