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

img




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. https://en.javamana.com/2022/02/202202130720297502.html