Write a java program to read n integers into LinkedList collection Do the following operations i) Display only negative integers ii) Delete the last element

import java.io.*;
import java.util.*;
class Slip29
{
    public static void main(String ar[]) throws IOException
    {
        int n;
        BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
        System.out.print("\t\t Enter the size of Linked List ");
        n= Integer.parseInt(br.readLine());
        LinkedList<Integer> ll = new LinkedList<Integer>();
        for(int i=0;i<n;i++)
        {
           System.out.println("Enter the element ");
           ll.add(Integer.parseInt(br.readLine()));
        }
        Iterator<Integer> it = ll.iterator();
        System.out.println(" Contents of Linked List using iterator ");
        while(it.hasNext())
           System.out.println(" \t " + it.next());
        it = ll.iterator();
        System.out.println(" List of negative numbers ");
        while(it.hasNext())
        {
            int no=it.next();
            if(no<0)
               System.out.println("\t" + no);
        }
        ll.removeLast();
        it=ll.iterator();
           System.out.println(" Contents of linked list after removing last element... ");
        while(it.hasNext())
          System.out.println("\t" +it.next());
    }
}

6 comments:

  1. Nice to read your article! very informative post .So, please keep posting A dvanced Java Stuff here Thanks man.......

    ReplyDelete
  2. Wow amazing i saw the article with execution models you had posted. It was such informative. Really its a wonderful article. Thank you for sharing and please keep update like this type of article because i want to learn more relevant to this topic.

    VMWare Training in Chennai

    MSBI Training in Chennai

    ReplyDelete
  3. This is quite educational arrange. It has famous breeding about what I rarity to vouch. Colossal proverb.
    This trumpet is a famous tone to nab to troths. Congratulations on a career well achieved. This arrange is synchronous s informative impolites festivity to pity. I appreciated what you ok extremely here 


    Selenium training in bangalore
    Selenium training in Chennai
    Selenium training in Bangalore
    Selenium training in Pune
    Selenium Online training

    ReplyDelete

  4. All are saying the same thing repeatedly, but in your blog I had a chance to get some useful and unique information,
    I love your writing style very much, I would like to suggest your blog in my dude circle, so keep on updates.
    Java training in Btm layout
    Java training in Jaya nagar
    Java training in Electronic city
    Java training in Chennai
    Java training in USA

    ReplyDelete