This program help customer to buy the most expensive products from all the available in the shop. This program takes from user the available amount with him and cost of all the available products in the shop. Than it finally gives the index number of the products that are most suitable.
public class store_credit {
public static void main(String[] args) {
int credit = 100; /*This is the available credit to the user.*/
int total = 3; /*This is the total number of the products in shop.*/
int price[] = {5,75,25}; /*This is the price array of all the items.*/
int size = total;
int temp = 0;
int i;
int pos1=0,pos2=0;
for(i=0;i<size;i++) {
for(int j=0;j<size;j++) {
int t = price[i]+price[j];
if( t > temp && t <= credit && i != j) {
temp = t;
pos1 = i + 1;
pos2 = j + 1;
}
}
}
System.out.println("Case#1: "+pos1 + " "+pos2);
}
}
public class store_credit {
public static void main(String[] args) {
int credit = 100; /*This is the available credit to the user.*/
int total = 3; /*This is the total number of the products in shop.*/
int price[] = {5,75,25}; /*This is the price array of all the items.*/
int size = total;
int temp = 0;
int i;
int pos1=0,pos2=0;
for(i=0;i<size;i++) {
for(int j=0;j<size;j++) {
int t = price[i]+price[j];
if( t > temp && t <= credit && i != j) {
temp = t;
pos1 = i + 1;
pos2 = j + 1;
}
}
}
System.out.println("Case#1: "+pos1 + " "+pos2);
}
}