Concept explainers
It is a well-known phenomenon that most people are easily able to read a text whose words have two characters flipped, provided the first and last letter of each word are not changed. For example,
I dn’ot gvie a dman for a man taht can olny sepll a wrod one way. (Mrak Taiwn)
Write a method String scramble(String word) that constructs a scrambled version of a given word, randomly flipping two characters other than the first and last one. Then write a program that reads words and prints the scrambled words.
Want to see the full answer?
Check out a sample textbook solutionChapter 5 Solutions
Big Java Late Objects
Additional Engineering Textbook Solutions
Database Concepts (8th Edition)
Absolute Java (6th Edition)
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
Starting Out with Programming Logic and Design (4th Edition)
Starting Out with Java: Early Objects (6th Edition)
Introduction To Programming Using Visual Basic (11th Edition)
- Write the method catDog.* * Given a String str, return true if the words "cat" and "dog" appear the same* number of times in the string.* * Examples: catDog("catdog") returns true catDog("catcat") returns false* catDog("1cat1cadodog") returns true* * @param str the String to examine.* @return true if there are the same number of cats and dogs.arrow_forwardHello. I can't get this Java code to work. It takes a series of sentences as a single string. The function capitalizes the first letter of every sentence What am I doing wrong? /*Programming ChallengesChapter 9 #3 Pg. 608 Title: Sentencee CapitallizerWrite a method that accepts a String object as an argument and returns a copy of the stringwith the first character of each sentence capitalized. For instance, if the argument is “hello.my name is Joe. what is your name?” the method should return the string “Hello. My nameis Joe. What is your name?” Demonstrate the method in a program that asks the user toinput a string and then passes it to the method. The modified string should be displayed onthe screen.*/ import javax.swing.JOptionPane; public class SentenceCapitalizer{public static void main(String[] args){String input;input = JOptionPane.showInputDialog("Enter a string.");JOptionPane.showMessageDialog(null, sentenceCap(input));System.exit(0);} public static String sentenceCap(String…arrow_forwardJava program I need help writing a program that has 3 methods: the main method, a method that swaps the digit pairs, and another method that swaps letter pairs. first you would ask the user for a number and call the method that swaps the digit pairs to swap the number shown in the picture. Then ask the user to input a string of letters and numbers and call the method that swaps lettter pairs to swap the letters as shown in the picture. in the method that swaps digit pairs, it accepts an integer for its parameter and then returns a new integer that has each pair of digits swapped in order. if it is an odd number of digits, leave the leftmost digit in its original place. the method that swaps digit pairs shouldnt use the string class. but for the swap letter pairs, it is similar operation as the swap digit pairs method but accepts a string as a parameter and return the swapped string. it can use string class.arrow_forward
- java: Run length coding is a method to represent a string in a more compact manner. Each character that occurs more than 2 times in a row is represented by the character and a number following it. Two examples are: "abba" → "abba""abcccbbbba" → "abc3b4a"Write a function that calculates how many characters the encoded string is shorter than the original.arrow_forwardin python "AnagramMake a method is_anagram_of(a,b) that tests if a is an anagram of b.A string a is an anagram of a string b, if it uses exactly the same letters, but the order can be different.Spaces are ignored, as well as capitalization.Examples of anagrams:"eleven plus two" - "twelve plus one""William Shakespeare" - "I am a weakish speller""Tom Marvolo Riddle" - "I am Lord Voldemort""Anagrams" - "Ars manga""television ads" - "enslave idiots"Counter examples:"bla" - "aalb""cat" - "tact"Hint: Make a dictionary that holds how often a letter occurs in a word."""def is_anagram_of(a, b):passarrow_forwardSolve in java Find the index of a string within a hex encoded string. You will be given a string which needs to be found in another string which has previously been translated into hex. You will need to return the first index of the needle within the hex encoded string. Examples firstIndex("68 65 6c 6c 6f 20 77 6f 72 6c 64", "world") → 6 firstIndex("47 6f 6f 64 62 79 65 20 77 6f 72 6c 64", "world") ➡8arrow_forward
- Assume you have a method i 5Su b 5 tr ing which checks if one word is a substring of another. Given two strings, 51 and 52, write code to check if 52 is a rotation of 51 using only one call to i5Sub5tring (e.g., "waterbottle" is a rotation of"erbottlewat").arrow_forwardWrite a Java program that asks the user to enter a string and counts how many times the letter "s" or "S" appears in the string. Display that number and then display the string that many times. Requirements: Call a method that gets the string from the user. Use recursion to ensure the string has at least 5 characters. Call a method that returns the number of times the letter "s" or "S" appears in the string. This method should use recursion. Call a method that takes the number of times the letter"s" or "S" appeared in the string and display the original string that was obtained from the user that many times using recursion. Call a method that sorts the letters in the string and searches for the letter "m". Display Found or Not Found.arrow_forwardGiven a string, write a method that returns the number of occurrences of substrings "baba" or "mama" in the input string recursively. They may overlap. Do not use any loops within your code. Do not use any regular expressions and methods such as matches, split, replaceAll. "Maa mana, Test case 1: countBabaMama ("aba babaa amama ma") 2 Test case 2: countBabaMama ("bababamamama") 4arrow_forward
- Eclipse Java: Write a program that reads a string (password) and a number. The maximum number of attempts (3). The program with stop asking data if the word ‘quit’ is provided in the password valuearrow_forwardIn java Language Write the method named shift3()* * You are given a String str. Return a new String where* all of the characters are "shifted" by 3. Here is the* algorithm to do this* 1. Visit each character in the String* 2. Create a new char by adding 3* 3. Store the new character in the output string** Examples:* shift3("hello") returns "khoor"* shift3("cat") returns "fdw"* shift3("frog") returns "iurj"** @param str the String to start with* @return the rotated String as described herearrow_forwardpublic static String reversevowels (String text) Given a text string, create and return a new string of same length where all vowels have been reversed, and all other characters are kept as they were. For simplicity, in this problem only the characters aeiouAEIOU are considered vowels, and y is never a vowel. For example, given the text string "computer science", this method would return "cempetir sceunco". Furthermore, to make this problem more interesting and the result look more palatable, this method must maintain the capitalization of vowels based on the vowel character that was originally in the position that each new vowel character is moved into. For example, "Ilkka Markus" should become "Ulkka Markis" instead of "ulkka MarkIs". Use the handy utility methods in the Character wrapper class to determine whether some particular character is in upper- or lowercase, and convert a character to upper- or lowercase as needed.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education