Question

In: Computer Science

How can I write java program code that do reverse, replace, remove char from string without...

How can I write java program code that do reverse, replace, remove char from string without using reverse, replace, remove method.

Only string method that I can use are length, concat, charAt, substring, and equals (or equalsIgnoreCase).

Solutions

Expert Solution

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________

// ReverseReplaceRemoveCharDemo.java

import java.util.Scanner;

public class ReverseReplaceRemoveCharDemo {

   public static void main(String[] args) {
       String str,revStr="",afterReplaced="",charRemoved="";
       /*
       * Creating an Scanner class object which is used to get the inputs
       * entered by the user
       */
       Scanner sc = new Scanner(System.in);

       //Getting the input entered by the user
System.out.print("Enter String :");
str=sc.nextLine();
  
for(int i=str.length()-1;i>=0;i--)
{
   revStr+=str.charAt(i);
}

System.out.println("After reverse '"+str+"' is :"+revStr);
  
System.out.print("Enter string you want to replace :");
String replaceStr=sc.nextLine();
  
System.out.print("Enter string you want to replace with:");
String replaceWith=sc.nextLine();
  
int indx=str.indexOf(replaceStr);
if(indx!=-1)
{
   afterReplaced=str.substring(0,indx);
   afterReplaced+=replaceWith;
   afterReplaced+=str.substring(indx+1+replaceStr.length()-1,str.length());
   System.out.println("After replacing '"+replaceWith+"' , the new String is :"+afterReplaced);
}
else
{
   System.out.println("'"+replaceStr+"' is not substring of '"+str+"'");
}
  
System.out.print("Enter char to remove from '"+str+"':");
char ch=sc.next(".").charAt(0);
for(int i=0;i<str.length();i++)
{
   if(str.charAt(i)!=ch)
   {
       charRemoved+=str.charAt(i);
   }
}
System.out.println("String after removal of '"+ch+"' :"+charRemoved);
   }

}
___________________________

Enter String :you are so beautiful.
After reverse 'you are so beautiful.' is :.lufituaeb os era uoy
Enter string you want to replace :beautiful
Enter string you want to replace with:ugly
After replacing 'ugly' , the new String is :you are so ugly.
Enter char to remove from 'you are so beautiful.':a
String after removal of 'a' :you re so beutiful.

_______________Could you plz rate me well.Thank You


Related Solutions

I need to write java program that do replace first, last, and remove nth character that...
I need to write java program that do replace first, last, and remove nth character that user wants by only length, concat, charAt, substring, and equals (or equalsIgnoreCase) methods. No replace, replaceFirst, last, remove, and indexOf methods and letter case is sensitive. if user's input was "be be be" and replace first 'b' replace first should do "e be be" replace last should do "be be e" remove nth character such as if user want to remove 2nd b it...
Write a program to remove extra blanks from text files. Your program should replace any string...
Write a program to remove extra blanks from text files. Your program should replace any string of two or more blanks with one single blank. It should work as follows: * Create a temporary file. * Copy from the input file to the temporary file, but do not copy extra blanks. * Copy the contents of the temporary file back into the original file. * Remove the temporary file. Your temporary file must have a different name than any existing...
So I need to make a java program that reverse or replace first or lastchar or...
So I need to make a java program that reverse or replace first or lastchar or remove char from user's string input. length, concat, charAt, substring, and equals (or equalsIgnoreCase) thses are the string method that only I can use for example if user put asdf asdf and chose reverse input should be fdsa fdsa if user put asdf asdf and chose replace first a with b input should be bsdf asdf if user put asdf asdf and chose remove...
write a java program to Translate or Encrypt the given string : (input char is all...
write a java program to Translate or Encrypt the given string : (input char is all in capital letters) { 15 } *) Each character replaced by new character based on its position value in english alphabet. As A is position is 1, and Z is position 26. *) New characters will be formed after skipping the N (position value MOD 10) char forward. A->A+1= B , B->B+2=D ,C->C+3=F, .... Y->Y+(25%10)->Y+5=D A B C D E F G H I...
Parse string java code Write a recursive program that can calculate the value of a given...
Parse string java code Write a recursive program that can calculate the value of a given polynomial in a string, which is not more than the tenth order, for the given x. The polynomial will be given in the following format and should display the value of the polynomial for spaced-out x Using index of for -/+
Write a Java Program that can:​ Remove a particular element from an array.​ Add a new...
Write a Java Program that can:​ Remove a particular element from an array.​ Add a new element to an array.​ Change an element with the new one.​ Search for a particular element in the array.​ ​The code must have four separate methods for each task stated above.​ Do not use any pre-defined Java functions.​ You are free to use int or String data-type for the array.​
I need to write a C++ program that appends "not" into the string without using the...
I need to write a C++ program that appends "not" into the string without using the append method or any standard libraries. It should return the string if there isn't an "is" in it. Examples: is is = is not is not This is me = This is not me What is yellow? = What is not yellow? The sky is pink = The sky is not pink isis = isis What happened to you? = What happened to you?
Write a function void reverse(char * s) that reverses the string passed as an argument. Your...
Write a function void reverse(char * s) that reverses the string passed as an argument. Your code should use pointer arithmetic (it may increment and decrement pointers, but it may not use array indexing). Here is a piece of code that shows the behavior of reverse: char buf[100]; strcpy(buf, “hello”); reverse(buf); printf(“%s\n”, buf); // output should be olleh
Write a C program that can search for a string within a text file, replace it...
Write a C program that can search for a string within a text file, replace it with another string and put results in a new file.
Java Searching and Sorting, please I need the Code and the Output. Write a method, remove,...
Java Searching and Sorting, please I need the Code and the Output. Write a method, remove, that takes three parameters: an array of integers, the length of the array, and an integer, say, removeItem. The method should find and delete the first occurrence of removeItem in the array. If the value does not exist or the array is empty, output an appropriate message. (After deleting an element, the number of elements in the array is reduced by 1.) Assume that...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT