1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
malfutka [58]
3 years ago
9

Complete the firstMiddleLast() function to return a new string with the first, middle, and last character from string. If string

has an even number of characters, grab the middle two characters. It is safe to assume that no string passed in will be less than 3 characters.
Computers and Technology
1 answer:
morpeh [17]3 years ago
4 0

public static void main()

{

String s = Console.ReadLine();

int len = s.length();

Char startletter = s[0];

Char endletter = s[len-1];

string midletter = ‘’;

if(len % 2 ==0)

midletter = s[len/2] + s[(len/2) +1]

else

midletter = s[len/2];

Console.WriteLine(startletter + midletter + endletter);

}

Here the logic is that, startletter is obtained using the index ‘0’, the last letter is obtained by calculating the “length of the string” and subtract 1 to get the “last index” of the given string.

Middle letter is calculated by first finding whether the given string length is “odd or even” and based on that index(es) are identified.

You might be interested in
"the ____ criteria filter requires the records displayed to have the specified text string anywhere."
Debora [2.8K]

The contains criteria filter requires the records displayed to have the specified text string anywhere. Thecontains operator is used to perform case-sensitive matching regardless of location in strings.

The begins with criteria filter on the other hand requires the records displayed to start with the specified text string

3 0
3 years ago
Which of the following is NOT a Creative Commons license?
iogann1982 [59]
Commercial use is not a creative commons license
6 0
3 years ago
What will be a fundamental aspect of future games?
padilas [110]
D. product- oriented :))
6 0
3 years ago
Read 2 more answers
Write a function wordcount() that takes the name of a text file as input and prints the number of occurrences of every word in t
artcher [175]

Answer:

Explanation:

The following Python program uses a combination of dictionary, list, regex, and loops to accomplish what was requested. The function takes a file name as input, reads the file, and saves the individual words in a list. Then it loops through the list, adding each word into a dictionary with the number of times it appears. If the word is already in the dictionary it adds 1 to its count value. The program was tested with a file named great_expectations.txt and the output can be seen below.

import re

def wordCount(fileName):

   file = open(fileName, 'r')

   wordList = file.read().lower()

   wordList = re.split('\s', wordList)

   wordDict = {}

   for word in wordList:

       if word in wordDict:

           wordDict[word] = wordDict.get(word) + 1

       else:

           wordDict[word] = 1

   print(wordDict)

wordCount('great_expectations.txt')

4 0
3 years ago
A technician is dispatched to install additional RAM in a computer. The technician unplugs the system from the power source, and
xz_007 [3.2K]

Use an anti-static bag to hold the RAM while installing.

6 0
4 years ago
Other questions:
  • Explain Cascading Style Sheets and what they do. Describe their primary function, two effects that this function has on programm
    11·1 answer
  • What is the binding time for the following in C/C++ program. Explain. a. The location of memory of a local variable in a functio
    9·1 answer
  • Solve the following quadratic equation <br><br>y=6x^2-12x+1
    9·1 answer
  • What are the ASE special certifications?
    14·2 answers
  • Which type of choir often sings AND dances while they perform?
    9·1 answer
  • Which one is the answer for the question.
    11·1 answer
  • Input two numbers and print their sum products difference division and remainder​
    9·1 answer
  • Which tool uses images and other visual elements to provide artistic
    9·1 answer
  • What are the features of the title bar for the Microsoft word application?​
    15·2 answers
  • 9.2 lesson practice ​
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!