Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started