alice and bob were buying chocolates.It was Alice turn today to buy Bob chocolates.Bob gives list A of N chocolates where A[i] denotes price of ith chocolate.Alice being on a tight budget asks Bob if he can remove a few chocolates.Bob allows him to remove some chocolate whose price is X(which Alice can decide).Please find the minimum amount alice has to pay today
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class BobAndAlice {
public static void main(String[] args) {
List<Integer>Alice=new ArrayList<>();
Alice.add(23);
Alice.add(11);
Alice.add(36);
Alice.add(17);
Alice.add(41);
Alice.add(9);
Alice.add(11);
Alice.add(18);
Alice.add(29);
Scanner in = new Scanner(System.in);
int price = 0;
System.out.println("Available candies with the prices: ");
for (Integer integer : Alice) {
System.out.print(integer+" ");
}
System.out.println("Please provide value of candy(from 1 to 9) and press Enter:");
price = in.nextInt();
in.close();
Alice.remove(price);
System.out.println("So now have candies with prices: ");
System.out.println();
for (Integer integer : Alice) {
System.out.print(integer+" ");
}
}
}
Comments
Leave a comment