Answer to Question #158685 in Java | JSP | JSF for Sahithi

Question #158685

Alice and Bob were buying some chocolates. It was Alice's turn today to buy Bob chocolates. Bob gives Alice A of N chocolates where A[i] denotes price of ith chocolates. Bob allows him to remove some chocolates whose price is X



1
Expert's answer
2021-01-27T09:36:23-0500
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;


public class AliceAndBob {


	public static void main(String[] args) {
		List<Integer>A=new ArrayList<>();
		A.add(23);
		A.add(11);
		A.add(36);
		A.add(17);
		A.add(41);
		A.add(9);
		A.add(11);
		A.add(18);
		A.add(29);
		Scanner input = new Scanner(System.in);
		int price = 0;
		System.out.println("We have candies with prices: ");
		System.out.println();
		for (Integer integer : A) {
			System.out.print(integer+" ");
		}
		System.out.println("\n");
		System.out.println("Please provide value of candy(from 1 to 9) and press Enter:");
		price = input.nextInt();
		input.close();
		A.remove(price);


		System.out.println("So now have candies with prices: ");
		System.out.println();
		for (Integer integer : A) {
			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