cabosun 0 Newbie Poster

Ok I have done the main section of my MergeSort program.

I have to accept 10 integers and put them into a list. I having trouble with inserting user input into a list.

Can anyone help?

import java.util.Scanner;
import java.util.LinkedList;  
 
import java.util.*;
public class mergesort{

public static class lp{
	int first;
	lp rest;

public lp(int f, lp r){
	
	first=f;
	rest=r;
}
}public static void show_list(lp p){
    
    if(p==null){
      System.out.println("null");
    }
     else {
      System.out.println(p.first);
      show_list(p.rest);
    }
  }
   public static lp merge(lp a, lp b){
     
     if(a==null)
       return b;
     
     if(b==null)
        return a; 
     
     if (a.first < b.first){
       return new lp(a.first, merge(a.rest,b));
     }
     else return new lp(b.first,merge(a,b.rest));
   }
   
  public static void main (String [] args){
  	
    lp list1 = new lp();
    
    
  	Scanner scanner = new Scanner(System.in);
  	System.out.println("input ten integers: ");
  	
  	// Part Where i have the problem reading input and putting
  	// into a list
  	for(int i=0; i<10; i++){
  		list1.add();
  	}
  	list1 = scanner.nextInt();
  	
  	
  }

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.