Java, find the minimum two numbers and output the absolute value of the difference

CSDN Q & A 2022-02-13 07:20:31 阅读数:742

java minimum numbers output absolute


Take the answer :

use for Loop to find the minimum .
Sort arrays from small to large , Take the first place directly , The second value can do these things .

Other answers 2:

Import required :import java.util.Arrays;

public static void main(String[] args) { int a[] = { 1, 5, 4, 8, 20 }; // Prioritize ( Default from small to large ) Arrays.sort(a); int res=Math.abs(a[0]-a[1]); System.out.println(" The result is :"+res);}
copyright:author[CSDN Q & A],Please bring the original link to reprint, thank you.