import java.util.*;
public class Main {
public static void main(String[] args) {
// write your code here
Scanner scan=new Scanner(System.in);
while(scan.hasNext()){
int n=scan.nextInt();
int res[]=new int[n];
for(int i=0;i<n;i++){
res[i]=scan.nextInt();
}
Arrays.sort(res);
System.out.println(res[n-1]+" "+res[0]);
}
}
} import java.util.*;
public class Main
{
public static void main(String [] args)
{
Scanner sc=new Scanner(System.in);
while(sc.hasNextInt())
{
int n=sc.nextInt();
int [] array=new int[n];
for(int i=0;i<n;i++)
{
array[i]=sc.nextInt();
}
int max=array[0];
for(int i=1;i<array.length;i++)
{
if(array[i]>max)
{
max=array[i];
}
}
int min=array[0];
for(int i=1;i<array.length;i++)
{
if(array[i]<min)
{
min=array[i];
}
}
System.out.println(max+" "+min);
}
}
} import java.util.Scanner;
import java.util.Arrays;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int n = sc.nextInt();
int[] nums = new int[n];
for(int i=0;i<n;i++){
nums[i] = sc.nextInt();
}
Arrays.sort(nums);
System.out.println(nums[n-1]+" "+nums[0]);
}
}
}
给一个基本都会的一个思路,虽然时间复杂度、空间复杂度不够优秀,但还是能解题的QAQ
import java.util.Scanner;
public class Main {
static int biggest(int[] a) {
int max = a[0];
for(int i = 1; i < a.length; i++) {
if(a[i] > max) {
max = a[i];
}
}
return max;
}
static int smallest(int[] a) {
int min = a[0];
for(int i = 1; i < a.length; i++) {
if(a[i] < min) {
min = a[i];
}
}
return min;
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
while(scan.hasNext()) {
int n = scan.nextInt();
int[] arr = new int[n];
for(int i = 0; i < n; i++) {
arr[i] = scan.nextInt();
}
System.out.println(biggest(arr) + " " + smallest(arr));
}
}
}