Add items in shopping cart:
We are using ArrayList
Code:
import java.util.*;
public class Main
{ public static void main (String[]args)
{
ArrayList < String > items = new ArrayList < String > ();
Scanner sc = new Scanner (System.in);
items.add ("folder");
items.add ("flower");
items.add ("Car");
items.add ("Bottle");
items.add ("Mask");
items.add ("Box");
System.out.println ("Shopping card items");
System.out.print (items);
System.out.println ("Enter item which you want:");
String rmv = sc.nextLine ();
items.remove (rmv);
System.out.println ("Shopping card items");
System.out.print (items);
}
}
Output:
Shopping card items
[folder, flower, Car, Bottle, Mask, Box]Enter item which you want:
flower
Shopping card items
[folder, Car, Bottle, Mask, Box]
Comments
Post a Comment