Answer to Question #159203 in Java | JSP | JSF for Bandoju Sindhu

Question #159203

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


1
Expert's answer
2021-01-28T12:23:51-0500
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+" ");
        }
    }
   
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog