P2
P2
*;
import java.util.*;
//productSmallestPair(sum,arr)
//eg sum=9,n=7,arr=5,2,4,3,9,7,1 o/p=2
//Implement the function to find the pair, (arr[j], arr[k]) where j!=k, Such that
arr[j] and arr[k] are the least two elements of array (arr[j] + arr[k] <= sum) and
return the product of element of this pair
// (2, 1) 2 + 1 = 3 < 9, Product of (2, 1) 2*1 = 2. Thus, output is 2
/*
public class Prepinsta1{
public static int productSmallestPair(int sum,int arr[],int n){
if(n<2){
return -1;
}
int check;
// for(int i=0;i<n;i++){//5,2,4,3,9,7,1
// for(int j=i+1;j<n;j++){
// if(arr[i]>arr[j]){
// temp=arr[i];
// arr[i]=arr[j];
// arr[j]=temp;
// }
// }
// }
Arrays.sort(arr);
check=arr[0]+arr[1];
if(check<=sum)
return arr[0]*arr[1];
else
return 0;
}
public static void main(String[] args){
int sum=9;
int arr[]={8,5,7,3,6,4};
int n=arr.length;
System.out.println(productSmallestPair(sum,arr,n));
}
}*/
/*
//to move hypen in front of the string
//eg=> String-Compare 0/p=> -StringCompare
class Prepinsta1{
public static String moveHypenFront(String str,int n){
String result ="";
for(int i=0;i<n;i++){
if(str.charAt(i)=='-')
result=str.charAt(i)+result;
else
result=result+str.charAt(i);
// return str;
}
return result;
}
public static void main(String[] args){
String str="StringCompare";
int n=str.length();
System.out.println(moveHypenFront(str,n));
}
}*/
len_a--;
}
if (len_b > 0)
{
y = b.charAt(len_b - 1)-'0' ;
System.out.println(" "+y);
len_b--;
}
return count;
}
public static void main(String[] args){
int num1=451;
int num2=349;
System.out.println(numberOfCarries(num1,num2));
}
}
*/
Collections.sort(even);
Collection.sort(odd);
System.out.println("sorted even elements ");
for(e:even){
System.out.println(e+" ");//1,3,9
}
for(o:odd){
System.out.println(o+" ");
}