Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions