題目:
代碼:
import java.util.Scanner;
public class MiniDif {
public static void main(String[] args) {
int n;
int[] values;
Scanner scan = new Scanner(System.in);
n = scan.nextInt();
values = new int[n+1];
for(int i=1;i<=n;i++) {
values[i] = scan.nextInt();
}
md(values);
}
public static void md(int[] values) {
Integer minimum = Integer.MAX_VALUE;
int difference;
for(int i=1;i<=values.length-2;i++)
for(int j=i+1;j<=values.length-1;j++) {
difference = Math.abs(values[i]-values[j]);
if(difference < minimum)
minimum = difference;
}
System.out.println(minimum);
}
}
主類名稱改為Main