Question: Two strings, name 1 and name 2 , are read from input as two friends' names. headObj has the default value of name. Create a
Two strings, name and name are read from input as two friends' names. headObj has the default value of "name". Create a new node firstFriend with string name and insert firstFriend after headObj. Then, create a second node secondFriend with string name and insert secondFriend after firstFriend.
Ex: If the input is Ben Tia, then the output is:
name
Ben
Tia import java.util.Scanner;
public class FriendLinkedList
public static void mainString args
Scanner scnr new ScannerSystemin;
FriendNode headObj;
FriendNode firstFriend;
FriendNode secondFriend;
FriendNode currFriend;
String name;
String name;
name scnrnext;
name scnrnext;
headObj new FriendNodename;
Your code goes here
currFriend headObj;
while currFriend null
currFriend.printNodeData;
currFriend currFriend.getNext;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
