Question: Java Language Two strings, name 1 and name 2 , are read from input as two friends' names. headObj has the default value of name.

Java Language
Two strings, name1 and name2, are read from input as two friends' names. headObj has the default value of "name". Create a new node firstFriend with string name1, and insert firstFriend after headObj. Then, create a second node secondFriend with string name2, and insert secondFriend after firstFriend.
Ex: If the input isDel Gus, then the output is:
name
Del
Gus
import java.util.Scanner;
public class FriendLinkedList {
public static void main(String[] args){
Scanner scnr = new Scanner(System.in);
FriendNode headObj;
FriendNode firstFriend;
FriendNode secondFriend;
FriendNode currFriend;
String name1;
String name2;
name1= scnr.next();
name2= scnr.next();
headObj = new FriendNode("name");
****** 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 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!