Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

HELP IN JAVA: Write programs using the java built in Linked List class to do the

ID: 3882432 • Letter: H

Question

HELP IN JAVA: Write programs using the java built in Linked List class to do the following: 1. Collect 5 Strings from the keyboard and add them to a list. 2. Create a file of (unsorted) integers. Input them into a list so the list is sorted. Have at least 10 integers in your input file, but make your program work for any input file – meaning don’t use a for loop. 3. Use the file you created (above) as input. Create an array (of size 2) of Linked Lists (this is to help you with the homework question). Call this array A, and put all the odd numbers in the Linked List A[0], and all the even ones in A[1]. HELP IN JAVA: Write programs using the java built in Linked List class to do the following: 1. Collect 5 Strings from the keyboard and add them to a list. 2. Create a file of (unsorted) integers. Input them into a list so the list is sorted. Have at least 10 integers in your input file, but make your program work for any input file – meaning don’t use a for loop. 3. Use the file you created (above) as input. Create an array (of size 2) of Linked Lists (this is to help you with the homework question). Call this array A, and put all the odd numbers in the Linked List A[0], and all the even ones in A[1]. Write programs using the java built in Linked List class to do the following: 1. Collect 5 Strings from the keyboard and add them to a list. 2. Create a file of (unsorted) integers. Input them into a list so the list is sorted. Have at least 10 integers in your input file, but make your program work for any input file – meaning don’t use a for loop. 3. Use the file you created (above) as input. Create an array (of size 2) of Linked Lists (this is to help you with the homework question). Call this array A, and put all the odd numbers in the Linked List A[0], and all the even ones in A[1]. Write programs using the java built in Linked List class to do the following: 1. Collect 5 Strings from the keyboard and add them to a list. 2. Create a file of (unsorted) integers. Input them into a list so the list is sorted. Have at least 10 integers in your input file, but make your program work for any input file – meaning don’t use a for loop. 3. Use the file you created (above) as input. Create an array (of size 2) of Linked Lists (this is to help you with the homework question). Call this array A, and put all the odd numbers in the Linked List A[0], and all the even ones in A[1].

Explanation / Answer


import java.io.File;
import java.io.FileNotFoundException;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.Scanner;

/**
*
* @author Namburi Ramesh
*/
public class LList {
public static void main(String args[]) throws FileNotFoundException{
Comparator<Integer> order = Integer::compare; //used for sorting the linkedlist
Scanner ks=new Scanner(System.in); //used for taking the input from keyboard
Scanner fs1=new Scanner(new File("C:\A1.txt")); //used for taking the input from file
Scanner fs2=new Scanner(new File("C:\A1.txt")); //used for taking the input from file
  
LinkedList<String> stringList=new LinkedList<String>();
LinkedList<Integer> intList=new LinkedList<Integer>();
LinkedList<Integer>[] A=new LinkedList[2];
A[0]=new LinkedList<Integer>();
A[1]=new LinkedList<Integer>();
//Adding 5 strings to the LinkedList
System.out.println("Enter 5 Strings");
for(int i=0;i<5;i++){
stringList.add(ks.nextLine());
}
  
//Adding integers from file into LinkedList in sorted order
while(fs1.hasNext()){
intList.add(fs1.nextInt());
}
intList.sort(order);
  
//Adding integers from file into array of linked lists
while(fs2.hasNext()){
int a=fs2.nextInt();
if(a%2==0){
A[1].add(a);
}else{
A[0].add(a);
}
  
}
  
  
}
}