Given a string, if the same 2-character substring appears at both its beginning and end, return the contents of the string without the 2-character substring at the beginning. For example, "HelloHe" yields "lloHe". Note that the 2-character substring at the beginning may overlap with the one at the end, so "Hi" yields "". If the two characters at the start and end of the string do not match each other, return the original string unchanged.
def checkCharacters(a):
first = a[0:2]
second = a[-2:]
if first == second:
return a[2:]
else:
return a
Given a string, if the same 2-character substring appears at both its beginning and end, return...
public static int countCharacter(String str, char c) { // This recursive method takes a String and a char as parameters and // returns the number of times the char appears in the String. You may // use the function charAt(int i) described below to test if a single // character of the input String matches the input char. // For example, countCharacter(“bobbie”, ‘b’) would return back 3, while // countCharacter(“xyzzy”, ‘y’) would return back 2. // Must be a RECURSIVE...
language is java
Restrictions: You are not allowed to use anything from the String, StringBuilder, or Wrapper classes. In general, you may not use anything from any other Java classes, unless otherwise specified. You are not allowed to use String literals in your code ("this is a string literal"). You are not allowed to use String objects in your code. The methods must be implemented by manipulating the data field array, The CSString Class: NOTE: Pay very careful attention to...
Please I need help. Java language Method name: getScores Return value is a String of numbers scaled so that the highest number in the parameter String becomes 100 and all the other numbers are moved up by the same amount. This String should also be numbers separated by spaces with no additional characters. The order of the numbers should stay the same, so that a number in the original string has the equivalent scaled number in the returned string in...
Please read the problem carefully and answer the 2 questions
below
code:
/*****************************************************************
* Program: palindrome.c
*
* Purpose: implements a recursive function for determining
* if a string is a palindrome
*
* Authors: Steven R. Vegdahl, Tammy VanDeGrift, Martin Cenek
*
*****************************************************************/
#include
#include
#include
/*****************************************************************
* is_palindrome - determines whether a string of characters is a
palindrome
*
* calling sequence:
* result = is_palindrome(str, first_index,
last_index)
*
* parameters -
* str - the string to test
* first_index -...
Write a Python program (remove_first_char.py) that removes the first character from each item in a list of words. Sometimes, we come across an issue in which we require to delete the first character from each string, that we might have added by mistake and we need to extend this to the whole list. Having shorthands (like this program) to perform this particular job is always a plus. Your program should contain two functions: (1) remove_first(list): This function takes in a...
Assignment 1) Your function will only write the Nth character of the array, supplied as a parameter by the caller. This is an example prototype (although you may want to change the return value type, based on the second twist, below). void writeArrayNthBackward(const char [], int, int, int); The first three arguments serve the same purpose as in the iterative example. The fourth argument (an int) supplies the N for the Nth character to print in the array. If n...
2. This question is about processing strings 2.1 [4 marks] Given a string str, we can calculate a checksum of the string by summing up the ASCII codes of the characters in the string. For example, the checksum of a string "apple" is 530, which equals to 'a' + 'p' + 'p' + 'l' + 'e' = 97 + 112 + 112 + 108 + 101. Write a function int calculate_checksum(char str[] that calculates and returns the checksum of the...
Detecting Substrings (C++ Version) Introduction A very common task that is often performed by programs that work with text files is the problem of locating a specific substring within the file. I am sure we’ve all done this many times when working with Word, Notepad, or other editors. Since we don’t have a GUI or other means of displaying the contents of a file all at once, let’s modify the problem slightly. Rather than locating a specific substring within a...
Write a program that replace repeated three characters in a string by the character followed by 3. For example, the string aabccccaaabbbbcc would become aabc3ca3b3cc. When there are more than three repeated characters, the first three characters will be replaced by the character followed by 3. You can assume the string has only lowercase letters (a-z). Your program should include the following function: void replace(char *str, char *replaced); Your program should include the following function: void replace(char *str, char *replaced);...
Please help me. package a1; public class Methods { /* * Instructions for students: Use the main method only to make calls to the * other methods and to print some testing results. The correct operation of * your methods should not depend in any way on the code in main. * * Do not do any printing within the method bodies, except the main method. * * Leave your testing code...