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
SCORPION-xisa [38]
3 years ago
13

Write a function string middle(string str) that returns a string containing the middle character in str if the length of str is

odd, or the two middle characters if the length is even. For example, middle ("middle") returns "dd".
Computers and Technology
1 answer:
Katen [24]3 years ago
6 0

Answer:

function getMiddle(s) {

return s.length % 2 ? s.substr(s.length / 2, 1) : s.substr((s.length / 2) - 1, 2);

}

// I/O stuff

document.getElementById("submit").addEventListener("click", function() {

input = document.getElementById("input").value;

document.getElementById("output").innerHTML = getMiddle(input);

});

Explanation:

// >>> is an unsigned right shift bitwise operator. It's equivalent to division by 2, with truncation, as long as the length of the string does not exceed the size of an integer in Javascript.

// About the ~ operator, let's rather start with the expression n & 1. This will tell you whether an integer n is odd (it's similar to a logical and, but comparing all of the bits of two numbers). The expression returns 1 if an integer is odd. It returns 0 if an integer is even.

// If n & 1 is even, the expression returns 0.

// If n & 1 is odd, the expression returns 1.

// ~n & 1 inverts those two results, providing 0 if the length of the string is odd, and 1 if the length of the sting is even. The ~ operator inverts all of the bits in an integer, so 0 would become -1, 1 would become -2, and so on (the leading bit is always the sign).

// Then you add one, and you get 0+1 (1) characters if the length of the string is odd, or 1+1 (2) characters if the length of the string is even.

You might be interested in
What percentage of jobs work in the entertainment industry?
Masja [62]
Your answer is A hope this helps
6 0
3 years ago
In a(n) _________ program a student must pass an exam at the end of the course with a 3out if 5 in order to get college credit.
zlopas [31]

Answer:

Its an AP program.

Explanation:

7 0
3 years ago
Read 2 more answers
A day has 86,400 seconds (24*60*60). Given a number of seconds in the range of 0 to 1,000,000 seconds, output the time as days,
HACTEHA [7]

Answer:

// here is code in c++.

// include headers

#include <bits/stdc++.h>

using namespace std;

// function that calculate days, hours, minutes and seconds

void howLong(int sec)

{

   // find days

   int days=sec/86400;

   // update the seconds

   sec=sec%86400;

   // find hours

   int h=sec/3600;

   // update the seconds

   sec=sec%3600;

   // find minutes

   int min=sec/60;

   // update the seconds

   sec=sec%60;

   // output

   cout<<sec<<"seconds is "<<days<<" days,"<<h<<" hours,"<<min<<" minutes,and "<<sec<<"seconds."<<endl;

}

// driver function

int main()

{   // variable

   int sec;

   cout<<"Enter seconds:";

   // read the seconds

   cin>>sec;

   // call the function

   howLong(sec);

   

return 0;

}

Explanation:

Read the seconds from user.Then call the function howLong() with parameter seconds. In the function, it will first find the number of days by dividing the seconds with 86400 then update the remaining seconds.Next it will find the hours by dividing the remaining seconds with 3600 and update the remaining seconds.After that it will find the minutes by dividing the remaining seconds with 60 and update the remaining second.Then it will print the days, hours, minutes and seconds.

Output:

Enter seconds:70000

40seconds is 0 days,19 hours,26 minutes,and 40seconds.

3 0
3 years ago
Read 2 more answers
What is the difference between an interpreted and a compiled language?
Sauron [17]

Answer:

The interpreted language is a programming language that is typically processed rather than compiled into machine code. It is one in which the instructions are received and processed by another program rather than directly performed by the client computer. JavaScript, Perl, Python, BASIC, and other interpretable languages. A compiled language is a programming language that is typically compiled rather than interpreted. It is one in which the software, once built, is represented in the target machine's code; this machine code is indecipherable by people. C, C++, C#, and other compiled languages.

4 0
2 years ago
Jeff types a sentence “She wore a dress yesterday.” He erroneously typed w instead of e for dress. What is the accuracy of the t
jok3333 [9.3K]
A would be you’re awnser.
5 0
3 years ago
Other questions:
  • The part of the computer that provides access too the internet is?
    10·2 answers
  • • What advantage does a circuit-switched network have over a packet-switched network? What advantages does TDM have over FDM in
    12·1 answer
  • Suppose you are an ISP that owns a / 22 IPv4 address block. Can you accommodate requests from six customers who need addresses f
    8·1 answer
  • What summarizes a data source into a grid of rows and columns?
    12·2 answers
  • Narrate an incident from the experience of a 14 year old girl which brings out the message: " Never leave till tomorrow what you
    10·1 answer
  • Columns, margins and orientation can all be found on what tab?
    15·1 answer
  • Choose all that apply.
    5·2 answers
  • The relational algebra expressions can be rearranged and achieve the same result but with a better processing time. A selection
    8·1 answer
  • Explain the working principle of computer with suitable diagram​
    15·1 answer
  • Re-write the below program correcting the bugs
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!