Write a program to take a String as input then display the first and last letter of each word with a condition that if it is having one character then it will remain as it is using only indexOf() function.
For example:
Enter a String
ASia is A conTinEnT
Modified: Aa is A cT
Write a program to take a String as input then display the position of a particular character given as input using indexOf() function of String class. Don't use charAt() function.
Enter a String
JapanIsSupremE
Enter character to find: e
Index Position: 11
Write a program to take a String as input then display the palindrome word in one column and its position in another column.
Example:
Enter a String
My Mom brought a racecar
Mom \t 2
racecar \t 5
for(i=0;i<l;i++) {
c = s.charAt(i);
if(c != ' ') {
w=w+c;
r=r+c;
} else {
if(w.compareToIgnoreCase(r)==0)
w=""; r=""; //Use this code to search palindrome words
Write a program that has two functions: the main function and a function, called sumOfSquared(n), that takes an integer number (read in the main function uisng input) and calculates the total sum of squares of all numbers from 1 to a given number. Then, it returns the result to the main function. Finally, the result should be printed.
Final Project - TicTacToe Human vs. Computer 2 # 3 # Purpose: using a nested list structure to store a 3x3 grid of values 4 # simulate a childhood game of tic-tac-toe. The human player interacts 5 # with a full command line interface to select board positions.
the goal of this coding exam is to quickly get off you the ground with the array method every().
input
output
input1
[{'name': 'Blake Hodges', 'points':[76, 98, 88, 84]},[{'name': 'James Anderson', 'points':[0, 98, 12, 33]},[{'name': 'Matthew Norton', 'points':[89, 67, 83, 93]}
output1
['Blake Hodges]
function readLine() {
return inputString[currentLine++];
}
function main() {
const candidatesList = JSON.parse(readLine().replace(/'/g, '"'));
/* Please do not modify anything above this line */
// Write your code here
}
Area of a Sub-matrix
You are given an M*N matrix and K, write a program to compute the area of the sub-matrix and print the result.
A sub-matrix is a matrix formed after deleting K rows each from the top and bottom and K columns each from left and right.
Area of a matrix is defined as the product of all elements of the matrix.
Explanation
For M = 5 and N = 4, the matrix is:
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
17 18 19 20
For K = 1, the sub-matrix is as follows:
6 7
10 11
14 15
Therefore, the area of the matrix is 6*7*10*11*14*15 = 970200.
Sample Input1
5 4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
17 18 19 20
1
Sample Output1
970200
New Dictionary
Peter is making a new dictionary.He wants to arrange the words in the ascending order of their length and later arrange the ones with the same length in lexicographic order.Each word is given a serial number according to its position.Find the word according to the serial number.
Input
The first line of input is a positive integer which is the serial number.
Output
The output should be a single line containing the word that represents the serial number.
Explanation
Given serial number is 42.
As the serial number is between 26 and 52, the first character of the word is A.The remaining counter of the serial number is 16 (42-26).
The second character of the word is the 16th alphabet, which is P.
So, the output should be AP.
Sample Input1
42
Sample Output1
AP
Sample input2
751
Sample output2
ABW
The volume of a sphere is 4/3πr3, where π has the value of "pi" given in Section 2.1 of your textbook. Write a function called print_volume (r) that takes an argument for the radius of the sphere, and prints the volume of the sphere.
Call your print_volume function three times with different values for radius.
Include all of the following in your Learning Journal:
Product of the String
You are given an alphanumeric string S.Write a program to multiply all the charcters(except trailing zeroes) in S and print the output.
Rules for multiplication:
Input
The first line contains a string S.
Output
The output should be a integer denoting the product of characters.
Explanation
For N = 123a4
ASCII value of a is 97.
Product of digits of ASCII value of a is 9 *7 = 63.
Therefore the product of characters is 1*2*3*4*63*4 = 1512.
Sample Input1
123a4
Sample Output1
1512