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
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+" ");
}
}
}
Comments
Leave a comment