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 :");...



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:



LinkedListlinkedlist=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



{



// 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



{



// 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



{



// 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



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");



}



}



}



}




Jun 03, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here