Question

Write a program code with method stringX(String str) in Java using loops to removes the ‘x’...

Write a program code with method stringX(String str) in Java using loops to removes the ‘x’ s in a string. If a string starts and ends with ‘x’, keep that x.

Use only loops and if statements. Please provide an explanation. Thanks!!!

Examples:

stringX(“abxxxcd”) returns “abcd”

stringX(“xkittenx”) returns “xkittenx”

stringX(“x”)” returns “x”

stringX(“xcaptainxhelloxhix”) returns “xcaptainhellohix”

0 0
Add a comment Improve this question Transcribed image text
Answer #1

apple- vi sam1.java 157x47 import java.lang.* import java.util.Scanneri public class sami f public static void main(String arapple- vi sam1.java 157x47 public static void main(Stringl args) f boolean firstsfalse,last=false; Scanner sc=new Scanner(Sysapple _-bashー157x47 apples-MacBook-Air:~ apples-MacBook-Air: Jaswanth$ Jaswa nth$ vi saml.java java sami abcd apples-MacBook-

Add a comment
Know the answer?
Add Answer to:
Write a program code with method stringX(String str) in Java using loops to removes the ‘x’...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Need help creating a basic java string program using nested if/else, return loops or while loops...

    Need help creating a basic java string program using nested if/else, return loops or while loops or charAt methods while returning information using a console, Please leave notes as to compare my program and see where I went wrong or could've used a different method. secondsAfterMidnight Input: String that represents time of day Returns: integer number of seconds after midnight (return -1 if String is not valid time of day) General time of day format HH:MM:SS(AM/PM) These are examples where...

  • The following code is a C Program that is written for encrypting and decrypting a string....

    The following code is a C Program that is written for encrypting and decrypting a string. provide a full explanation of the working flow of the program. #include <stdio.h> int main() { int i, x; char str[100]; printf("\n Please enter a valid string: \t"); gets (str); printf ("\n Please choose one of the following options: \n"); printf ("1 = Encrypt the given string. \n"); printf("2 = Decrypt the entered string. \n"); scanf("%d",&x); // using switch case statements switch (x) {...

  • Write a program using java that determines whether an input string is a palindrome; that is,...

    Write a program using java that determines whether an input string is a palindrome; that is, whether it can be read the same way forward and backward. At each point, you can read only one character of the input string; do not use an array to first store this string and then analyze it (except, possibly, in a stack implementation). Consider using multiple stacks. please type out the code :)

  • NO LOOPS, write a program, in Java, that prompts the user for a hexadecimal string of...

    NO LOOPS, write a program, in Java, that prompts the user for a hexadecimal string of EXACTLY 4 hex digits, no more, no less, converts the hexadecimal value to its decimal value using string, character parsing, and Math methods learned in this chapter, and then prints the original string and its converted decimal value. NOTE: Hex digits may be in UPPER or lower case.

  • You need to write a program (one java class containing Main calling function isPalindrome (String str)....

    You need to write a program (one java class containing Main calling function isPalindrome (String str). The function isPalindrome (returns Boolean T/F) needs to determine whether or not a string is a palindrome, using recursion. The algorithm to check whether a string is a palindrome is shown below: /* check for first and last char of String: * if they are same then do the same thing for a substring * with first and last char removed. and carry on...

  • I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that a...

    I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that accepts one integer parameter and returns the value raised to the third power as an integer. o Write a method called randominRange that accepts two integer parameters representing a range. The method returns a random integer in the specified range inclusive. 2. o Write a method...

  • C++ Write a recursive function that reverses the given input string. No loops allowed, only use...

    C++ Write a recursive function that reverses the given input string. No loops allowed, only use recursive functions. Do not add more or change the parameters to the original function. Do not change the main program. #include <iostream> #include <string> using namespace std; //Write a recursive function 'void reverse(string &str)' that reverses the given input string. void reverse(string &str) { /*Code needed*/ } int main() {    string name = "sherry";    reverse(name);    cout << name << endl; //should...

  • Lab 6                                    Given the String String str = “Zhrx.aghkio.G

    Lab 6                                    Given the String String str = “Zhrx.aghkio.Gko123”; (a) Write Java code using the String class methods indexOf and substring to extract the three string surrounded by the periods. In other words String s1 will contain Zhrx, String s2 will contain aghkio and String s3 will contain Gko123. (b) Write a method of the form public static String minStr(String str1, String str2) which returns the string which is “smaller” based on the decimal values of the characters in...

  • Using python, create a program using nested loops to write a function called substring(s,b) that returns...

    Using python, create a program using nested loops to write a function called substring(s,b) that returns True or False depending on whether or not b is a substring of s. For example: String: "Diamond" Substring: "mond" The code will then state that this is true and "mond" is a substring of "Diamond". Example of what the program should output: Enter string: Tree Enter substring: Tre Yes, 'Tre' is a substring of 'Tree' Limitation: This program cannot use "find()" and "in"...

  • Using Java only Implement a program that uses a recursive method to print a string backward....

    Using Java only Implement a program that uses a recursive method to print a string backward. Your program must contain a recursive method that prints the string backward. Use appropriate parameters in your method.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT