201712-1 CCS-CSP模擬試題 最小差值
阿新 • • 發佈:2018-12-11
import java.util.Scanner; public class Main { public static void main(String[] args){ int index=10000; int n; Scanner s = new Scanner(System.in); n = s.nextInt(); int[] value = new int[n]; for(int i=0; i<n; i++){ value[i] = s.nextInt(); } for(int i=0; i<n; i++){ for(int j=i+1; j<n; j++){ if(Math.abs(value[i]-value[j]) < index){ index = Math.abs(value[i]-value[j]); } } } System.out.printf("%d",index); } }