chocolate distribution problem
package com.company;
import java.util.*;
public class Main {
public static void main(String[] args) {
// sum of subarray
Scanner sc = new Scanner(System.in);
int arr[]={7,3,2,4,9,12,56};
for(int i=0; i<arr.length-1; i++) {
int smallest = i;
for(int j=i+1; j<arr.length; j++) {
if(arr[j] < arr[smallest]) {
smallest = j;
}
}
//swap
int temp = arr[smallest];
arr[smallest] = arr[i];
arr[i] = temp;
}
//choclate problem
//{2,3,4,7,9,12,56}
int m=3;
int n=arr.length;
for(int l=0; l<m; l++){
System.out.println(arr[l]);
}
int diff=arr[m-1]-arr[0];
System.out.println("diffrence of the two numbers is : " + diff);
}
Comments
Post a Comment