For the first question, you would just add the parenthesis to the string mutation1:
String word = "sadly";
String mutation1 = "(" + word + ")";
For the second you need the method substring from the String class:
It is defined as String.substring(begining, ending);
String name = "Smith";
String firstCharacter = name.substring(0, 1);
0 is considered the beginning of the string, then you get the next 1 characters.
Answer:20*i
Explanation:
Because the size will expand as its being written out to then have i
Answer:
let n = 10;
let sum = 0;
for(i=1; i<=n; i++) {
if ((i%5) && (i%7)) {
sum += i;
}
}
console.log(`Sum 1..${n} excluding 5 and 7 multiples is ${sum}`);
Explanation:
This is in javascript.
example output:
Sum 1..10 excluding 5 and 7 multiples is 33
Answer:
// program in C++.
#include <bits/stdc++.h>
using namespace std;
// main function
int main()
{
// string array
string m[3];
// array to store rainfall
double rainfall[3];
// variables
double avg_rainfall,sum=0;
for(int i=0;i<3;i++)
{
cout<<"Enter name of month "<<i+1<<" :";
// read month name
cin>>m[i];
cout<<"Enter rainfall (inches) in month "<<i+1<<" :";
// read rainfall
cin>>rainfall[i];
// sum of rainfall
sum+=rainfall[i];
}
// Average rainfall
avg_rainfall=sum/3;
// print Average rainfall
cout<<"Average rainfall for "<<m[0]<<","<<m[1]<<","<<m[2]<<" is "<<avg_rainfall<<" inches."<<endl;
return 0;
}
Explanation:
Create string array "m" to store name of month and double array "rainfall" to store rainfall. Read name of 3 months and rainfall in that month.Find the sum of all the rainfall and the average rainfall.Print the average rainfall of 3 months.
Output:
Enter rainfall (inches) in month 2 :45
Enter name of month 3 :july
Enter rainfall (inches) in month 3 :43
Average rainfall for may,june,july is 42.6667 inches.