im printing out my linkedList but the first element isnt printing why is that

import java.util.*;

public class Test

{

    static List<Integer> list  = new LinkedList<Integer>();

     public static void main(String[] args)

     {


        Scanner scanOne = new Scanner(System.in);

        System.out.println("Enter integers to be added to the list with a space between every number : ");
        String name = scanOne.next();

        Scanner scanTwo = new Scanner(scanOne.nextLine());


        while (scanTwo.hasNextInt())
        {
            list.add(scanTwo.nextInt());

        }

        print();


     }


    public static void print()
    {

        ListIterator<Integer> listIT = list.listIterator();    // using the list Interface's method "listIterator()" to Iterate through the listIT

        while(listIT.hasNext()) 
        {
            int n = listIT.next();
            System.out.print(n + " ");
        }
    }




}

Answers


You've made a simple error. You've called next() and then nextLine(), so the printing starts at the second element.

    String name = scanOne.next();
    Scanner scanTwo = new Scanner(scanOne.nextLine());

You don't add the first read element to the list:

String name = scanOne.next();

Read an int here and put it to the list as all the others.


Need Your Help

tfs2010 selenium - Unit testing against a previous build

selenium continuous-integration tfs2010

I use Selenium 2 (i.e. web driver) for unit testing in VS2010/TFS2010 environment. When the build (call it build # n) is triggered via checkin, the unit tests run (including Selenium ones) and after

cordova.js not working on remote page

php javascript cordova

I'm very new in phonegap and i'm working on simple remote index.php file. When i use the example code below in local index.html, it works. But when i use it on remote page, it's not working. i have...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.