BCA Slip29 Java

Java

Slip29

Q.1) Write a java program to accept n employee names from user, store them into the LinkedList class and display them by using. 
a. Iterator Interface 
b.  ListIterator Interface  [Marks 30] 

Solution

import java.io.*;
import java.util.*;

class Assgn29
{
public static void main(String ar[])throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("\nEnter No Of Elemrnts To Be Added:: ");
int no = Integer.parseInt(br.readLine());

LinkedList<String> ll = new LinkedList<String>();
for(int i = 0; i<no; i++)
{
System.out.print("\nEnter String: ");
String str = br.readLine();
ll.add(str);
}

Iterator<String> it = ll.iterator();
System.out.println("\n--------The Content Of LinkedList--------");
while(it.hasNext())
System.out.println("\t" + it.next());

ListIterator<String> lit = ll.listIterator();
    System.out.println("\n--------The Content Of LinkedList Using ListIterator--------");

while(lit.hasN
ext());
  System.out.println("\t"+ lit.next());
}
}
BCA Pratical Solution

My name is Vivek And I from Mumbai and Complete my Graduation Bca.my Age is 23 Years.

Post a Comment

Previous Post Next Post