Answered step by step
Verified Expert Solution
Link Copied!

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, 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 is Ben Tia, then the output is:
name
Ben
Tia 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

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

Step: 3

blur-text-image

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

Big Data, Mining, And Analytics Components Of Strategic Decision Making

Authors: Stephan Kudyba

1st Edition

1466568704, 9781466568709

More Books

Students also viewed these Databases questions

Question

=+ 2. What is the opportunity cost of seeing a movie?

Answered: 1 week ago

Question

=+ what roles should government play in them ?

Answered: 1 week ago

Question

=+ Why do we have markets and, according to economists,

Answered: 1 week ago