Question: Do correctly in java 1) Write a program to remove leading and trailing spaces from a string in Java Approach 1: To remove leading and

Do correctly in java

1)

Write a program to remove leading and trailing spaces from a string in Java

Approach 1:

To remove leading and trailing spaces in Java, use the trim() method. This method returns a copy of this string with leading and trailing white space removed, or this string if it has no leading or trailing white space.

Approach 2:

Remove the spaces without using the trim()

Sample Input: " Hi good evening "

Sample Output: "Hi good evening"

2)

Find the number occurring odd number of times

using nested loops

An array of non-negative integers. The task is to find the numbers that are occurring the odd number of times.

Input: arr = {1, 2, 3, 2, 5, 3, 1, 3, 2, 4, 5, 1, 4}

Output: 1, 2, 3

3)

Compute the Sum of Diagonals of a Matrix

using nested loops and array

The matrix has a row and column arrangement of its elements.

The principal diagonal is a diagonal in a square matrix that goes from the upper left corner to the lower right corner.

The secondary diagonal is a diagonal of a square matrix that goes from the lower left corner to the upper right corner.

Sample Input:

4 5 6 7

1 7 3 4

11 12 13 14

23 24 25 50

Sum principal diagonal elements: 74

Sum of secondary diagonal elements: 45

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!