import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int[] nums = new int[n]; int max = 0, min = 100; for (int i = 0; i < n; i++) { nums[i] = in.nextInt(); } for (int i = 0; i < n; i++) { if (max < nums[i]) { max = nums[i]; } if (min > nums[i]) { min = nums[i]; } } int ret = max - min; System.out.println(ret); } }
import java.util.Scanner; import java.util.ArrayList; import java.util.Arrays; import java.io.*; public class Main { public static void main(String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int a = Integer.parseInt(br.readLine()); String[] s = br.readLine().split(" "); ArrayList<String> inp = new ArrayList<>(Arrays.asList(s)); System.out.println( inp.stream().mapToInt(Integer::parseInt).max().getAsInt() - inp.stream().mapToInt(Integer::parseInt).min().getAsInt() ); } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int[] arr = new int[n]; for(int i = 0; i < n; i++) { arr[i] = in.nextInt(); } Arrays.sort(arr); System.out.println(arr[n - 1] - arr[0]); } }
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 while (in.hasNextLine()) { // 注意 while 处理多个 case String a = in.nextLine(); String n = in.nextLine(); String[] nList=n.split(" "); int max=0; int min=101; for(int i=0;i<nList.length;i++){ int tmp=Integer.valueOf(nList[i]); if(max<tmp){ max=tmp; } if(min>tmp){ min=tmp; } } System.out.print(max-min); } } }
import java.util.*; public class Main { //方法:冒泡排序(从小到大顺序) public static int[] maopao(int[] arr) { int temp = 0; for (int i = 0; i < arr.length - 1; i++) { for (int j = 0; j < arr.length - 1 - i; j++) { if (arr[j] > arr[j + 1]) { temp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = temp; } } } return arr; } //主程序:输入数组,调用冒泡,输出差 public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); } int[] arr1 = maopao(arr); System.out.print(arr1[n-1]-arr1[0]); } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while(scanner.hasNext()){ int toAddNumCount = scanner.nextInt(); //int maxSubmin = 0; int[] toNumArr = new int[toAddNumCount]; //输入数据 for(int i = 0;i < toNumArr.length;i++){ toNumArr[i] = scanner.nextInt(); } //初始化最大最小 int maxNum = toNumArr[0]; int minNum = toNumArr[0]; //比较后赋予真正的最大最小 for(int j = 0;j < toNumArr.length;j++){ if(maxNum < toNumArr[j]){ maxNum = toNumArr[j]; } if(minNum > toNumArr[j]){ minNum = toNumArr[j]; } } System.out.println(maxNum - minNum); } } }
import java.math.BigDecimal; import java.math.BigInteger; import java.util.HashSet; import java.util.Locale; import java.util.Random; import java.util.Scanner; public class Main{ public static void main(String [] args){ Scanner sc = new Scanner(System.in); while (sc.hasNext()){ Integer integer = sc.nextInt(); int i = 0; int it [] = new int[integer]; while (i<integer){ it[i++] = sc.nextInt(); } BubbleSort(it); System.out.println(it[it.length - 1] - it[0]); } } static public void BubbleSort(int array[]){ for(int i = 1;i<=array.length-1;i++){ for(int j=0;j<array.length-i;j++){ if(array[j]>array[j+1]){ int temp = array[j]; array[j] = array[j+1]; array[j+1] = temp; } } } } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { int n = sc.nextInt(); List<Integer> list =new ArrayList<>(); for (int i = 0; i < n; i++) { list.add(sc.nextInt()); } System.out.println(Collections.max(list) - Collections.min(list)); } } }
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 [] arr=new int[n]; for(int i=0;i<n;i++) { arr[i]=sc.nextInt(); } Arrays.sort(arr); System.out.println(arr[arr.length-1]-arr[0]); } } }