Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Walter
Waltido
1 Answer(s)      3 years ago
Posted in : Java Beginners


How do I write a program using a linked list, that will prompt a user to enter 10 names and display them reversed using output dialog boxes.


Advertisement
View Answers

September 15, 2011 at 3:22 PM


import java.util.*;
        import javax.swing.*;

        class  LinkedListExample
        {
            public static void main(String[] args) 
            {
                String names[]=new String[5];
                for(int i=0;i<names.length;i++){
                 names[i]=JOptionPane.showInputDialog("Enter name "+(i+1));
                }
                final LinkedList<String> list=new LinkedList<String>();

                for(int i=0;i<names.length;i++){
                    list.add(names[i]);
                }

                Collections.reverse(list);
                StringBuffer buffer=new StringBuffer();
                for(String name : list){
                  buffer.append(name);
                  buffer.append("\n");
                }
                JOptionPane.showMessageDialog(null,"List of names in reverse order: \n"+buffer.toString());
            }
        }


Related Tutorials/Questions & Answers:
Advertisements
Advertisements
 

 

 

DMCA.com