how to run this code
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
how to run this code
import java.util.*;
public class WordOp
{
publicstaticvoid main(string args[]);
{
Scanner sc = new Scanner(system.in);
system.out.print("Enter the word in lowercase letters :");
string word = sc.nextLine();
char c ;
string temp;
int count:
LinkedList<Character>linkedlist=New LinkedList<>();
while(true)
{
//ask the user for the choice of operation
system.out.print("\n*******Word Operations******\n1.Remove adjacent dupicate
character\n2.create LinkedList Vowels\n3.delete occurence of character\n4.search substring\n5.Display
the linked list in revers\n6.count occurrence of the character\n7.Diplays the content of the linked
list\n8.Exit\n.Enter your choice:");
int choice = sc.nextlnt();
// use a switch to execute statement of the respective choice
switch(choice)
{
case1 : C= Word.charAt(0);
temp = c+"";
// variable to maintain the count of removed characters
count = 0 ;
for (int i=1 : i<word.length : i++:");
{
// if the current character is not same as previous then add it to temp
if(Word.charAt(i)!=c)
{
temp=temp+word.charAt(i);
c=word.charAt(i);
}
else
count++;
}
word = temp;
System.Out.Println("Word: +"Word);
System.Out.Println("Number of characters removed: "+count);
break ;
case2 : LinkedList = New LinkedList<>();
String Vowels="aeiou";
for(int i=0 : i<word.length(): i++)
{
// check if the character is contained in the vowels string
if(vowels.contain(word.charAt(i)+""))
linkedlist.add(word.charAt(i));
}
system.out.print("Elements of linkedlist:");
for(char ch: linkedlist)
System.Out.Print(ch);
System.Out.Println();
break;
case3 : system.out.print("Enter the character:");
c=sc.next().charAt(0):
temp="";
for(int i=0 : i<word.length(): i++)
{
// if the character in not specified character then it add to temp
if(word.charAt(i)!=c)
temp=temp+word.charAt(i);
}
word=temp;
System.Out.Println("Word:"+Word);
break;
case4 : system.out.print("Enter the substring;" );
// after entering the choice, we press enter button which will generate \n character.
//this will be scanned by nextline() method which will give us a blank input hence
//we need to absorb this \n character with the below line
sc.nextLine();
//after that we will scan the nextLine
temp= sc.nextLine();
// use contains() method of string class to check if the substring is present in the word
//it will return true if the specified string is present in the word
if (word.contain(temp))
System.Out.println("the substring is present")
else
system.out.println("The substring is not present")
break;
case5 : // use temp to generate the linkedlist in reverse order
temp="";
system.out.print("Elements of linked list in reverse:");
//loop through each character present in the linkedlist
for(char ch: linkedlist)
temp=ch+temp: //contact the character in front of the temp string each time
system.out.println(temp);
break;
case6 : system.out.print("Enter the character:");
c=sc.next().charAt(0);
count=0;
//use a for loop and increment count if the current character is specified character
for(int i=0: i<word.length(): i++)
count++;
system.out.println("occurrence:+"+count);
break;
case7 : system.out.print("Elements of linkedlist:");
for (char ch:linkedlist);
system.out.print(ch);
system.out.println();
break;
case8 : // use exit () to close the program
system.exit(0);
default : system.out.println("Enter a valid choice");
}
}
}
}
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 11 images
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY