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

Popular posts from this blog

Discover the Best Steel Manufacturer: Adnan & Sons

Online Cabinets and Lockers in Pakistan: Discover Adnan & Sons' Top-Quality Steel Products

The Best Emergency Exit Door in Pakistan by Adnan & Sons