Question: * * MUST BE IN JAVA PLEASE * * Two integers, neighbors 1 and neighbors 2 , are read from input as the number of

**MUST BE IN JAVA PLEASE**
Two integers, neighbors1 and neighbors2, are read from input as the number of neighbors for two towns. headObj has the default value of -1. Create a new node firstTown with integer neighbors1, and insert firstTown after headObj. Then, create a second node secondTown with integer neighbors2, and insert secondTown after firstTown.
Ex: If the input is2812, then the output is:
-1
28
12
import java.util.Scanner;
public class TownLinkedList {
public static void main(String[] args){
Scanner scnr = new Scanner(System.in);
TownNode headObj;
TownNode firstTown;
TownNode secondTown;
TownNode currTown;
int neighbors1;
int neighbors2;
neighbors1= scnr.nextInt();
neighbors2= scnr.nextInt();
headObj = new TownNode(-1);
***** Your code goes here ******
currTown = headObj;
while (currTown != null){
currTown.printNodeData();
currTown = currTown.getNext();
}
}
}

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 Programming Questions!