Question: PLEASE HELP IN JAVA: Alter your program to make the code as efficient and modular as possible. Use ONE method to construct your first list,

PLEASE HELP IN JAVA:

Alter your program to make the code as efficient and modular as possible. Use ONE method to construct your first list, and ONE method to add a node to a list. YOU DO NOT NEED TWO METHODS (one for the odd list and one for the even list!!!)

Also, prepend is the easiest way to add to a list if you are not told otherwise.

newNode.next = head;

head = newNode;

This is an exercise in using nodes, so no extra credit for using linkedList class, lists etc.

Rubric:

* One method to get the integers and create first list

* one method (used three times) to add a node to a list

Program:

public static void main(String[] args) { //create a list called "list1" that conatains integers Scanner keyboard = new Scanner(System.in); Listlist1 = new ArrayList<>(); int n; System.out.println("Enter input numbers with space between each integer"); System.out.println(""); // add integers to list1 do{ n = keyboard.nextInt(); if(n==0){ break; } list1.add(n); } while (true); //display inputed integers System.out.print(" Inputed list of numbers are: "); for(int i =0; ieven = new ArrayList<>(); Listodd = new ArrayList<>(); //use for loop to determine whether an integer is even or odd for (int i =0; i

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!