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
marta [7]
2 years ago
10

2. Write a Java program that generates a new string by concatenating the reversed substrings of even indexes and odd indexes sep

arately from a given string. For this code you may use the above method to reverse the string. [10 points] Example #1 Input: abscacd Output: dasaccb Explanation: Substring are: asad, bcc Reversed substrings are: dasa, ccb Output: dasaccb
Engineering
1 answer:
Nana76 [90]2 years ago
4 0

Answer:

  1. public class Main {
  2.    public static void main(String[] args) {
  3.        String testString = "abscacd";
  4.        String evenStr = "";
  5.        String oddStr = "";
  6.        for(int i=testString.length() - 1; i >= 0; i--){
  7.            if(i % 2 == 0){
  8.                evenStr += testString.charAt(i);
  9.            }
  10.            else{
  11.                oddStr += testString.charAt(i);
  12.            }
  13.        }
  14.        System.out.println(evenStr + oddStr);
  15.    }
  16. }

Explanation:

Firstly, let declare a variable testString to hold an input string "abscacd" (Line 1).

Next create another two String variable, evenStr and oddStr and initialize them with empty string (Line 5-6). These two variables will be used to hold the string at even index and odd index, respectively.

Next, we create a for loop that traverse the characters of the input string from the back by setting initial position index i to  testString.length() - 1  (Line 8). Within the for-loop, create if and else block to check if the current index, i is divisible by 2, (i % 2 == 0), use the current i to get the character of the testString and join it with evenStr. Otherwise, join it with oddStr (Line 10 -14).

At last, we print the concatenated evenStr and oddStr (Line 18).  

You might be interested in
Which metal is used in planes.
wel

Answer:

<h2>Steel</h2>

Explanation:

Steel is the metal that using in planes.

Aluminum and titanium also used in this aircraft industry.

Aluminum is ideal for aircraft manufacture because it's lightweight and strong.

<em>hope</em><em> </em><em>this</em><em> </em><em>helps</em><em>!</em><em>!</em>

<em>have</em><em> </em><em>a</em><em> </em><em>nice</em><em> </em><em>day</em><em>!</em>

<em>follow</em><em> </em><em>me</em><em> </em><em>=</em><em>=</em><em>></em><em> </em><em>Hi1315</em>

5 0
2 years ago
Read 2 more answers
Plz solve the problem
julsineya [31]
I attached a photo that explains and gives the answer to your questions. Had to add a border because the whole picture didn’t fit.

6 0
3 years ago
PELASEE HELPPP WITH MARK BRAINLIST!!!! You are stopped at a red light, and a long string of cars is crossing in front of you. Wh
choli [55]

Answer:

1st one.

Explanation:

I think that because they the one who is going to get a ticket and also you will not gonna get in a car accident.

7 0
3 years ago
Read 2 more answers
Water is flowing at a rate of 0.15 ft3/s in a 6 inch diameter pipe. The water then goes through a sudden contraction to a 2 inch
Georgia [21]

Answer:

Head loss=0.00366 ft

Explanation:

Given :Water flow rate Q=0.15 \frac{ft^{3}}{sec}

         D_{1}= 6 inch=0.5 ft

        D_{2}=2 inch=0.1667 ft

As we know that Q=AV

A_{1}\times V_{1}=A_{2}\times V_{2}

So V_{2}=\frac{Q}{A_2}

     V_{2}=\dfrac{.015}{\frac{3.14}{4}\times 0.1667^{2}}

     V_{2=0.687 ft/sec

We know that Head loss due to sudden contraction

           h_{l}=K\frac{V_{2}^2}{2g}

If nothing is given then take K=0.5

So head lossh_{l}=(0.5)\frac{{0.687}^2}{2\times 32.18}

                                    =0.00366 ft

So head loss=0.00366 ft

4 0
2 years ago
Everyone why are you reporting my answers i didnt do anything to you
masya89 [10]

Answer:

IDK

Explanation:

same thing is happening to me

5 0
3 years ago
Read 2 more answers
Other questions:
  • What is the differences between stack and queue?
    11·1 answer
  • What is pessimism technology
    12·1 answer
  • A system consists of N very weakly interacting particles at a temperature T sufficiently high so that classical statistical mech
    9·1 answer
  • A simply supported beam spans 25 ft and carries a uniformly distributed dead load of 0.6 kip/ft, including the beam self-weight,
    15·1 answer
  • A thermistor is a temperature‐sensing element composed of a semiconductor material, which exhibits a large change in resistance
    13·1 answer
  • Consider a pipe with an inner radius of 5cm and an outer radius of 7cm.The inner surface is kept at 100C, and the outer surface
    11·1 answer
  • Write a method printShampooInstructions(), with int parameter numCycles, and void return type. If numCycles is less than 1, prin
    15·1 answer
  • A common chef's knife is single-beveled.<br> TRUE<br> FALSE
    10·1 answer
  • Please answwr the above question screenshot.​
    15·1 answer
  • A company intends to market a new product and it estimates that there is a 20% chance that it will be first in the market
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!