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]
3 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]3 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
The in situ moist unit weight of a soil is 17.3 kN/m3 and the moisture content is 16%. The specific gravity of soil solids is 2.
Temka [501]

Answer:

Explanation:

Given that,

Moist content w = 16%

The in situ moist unit weight of the soil : γ(in situ) = 17.3 kN/m³

Specific gravity of the soil

G(s) = 2.72

Minimum dry unit weight of the soil

γd(compacted) = 18.1 kN/m³

Moist content is same as above

w = 16%

Question

how many cubic meters of soil from the excavation site are needed to produce 2000 m³ of compacted fill?

Let determine the in situ dry unit weight γd(in-situ) using the relation

γd(in-situ) = γ(in-situ) / [1 + (w/100)]

γd(in-situ) = 17.3/ [1 + (18/100)]

γd(in-situ) = 17.3 / ( 1 + 0.18)

γd(in-situ) = 17.3 / 1.18

γd(in-situ) = 14.66 kN/m³

To determine the Volume of the soil to be excavated (Vex)

Let the Volume to be excavated = V

We can use the relation

V=V(fill) × γd(compacted) / γd(in situ)

Given that, V(fill) = 2000m³

V(fill) is the volume of the compacted fill

Therefore,

V=V(fill) × γd(compacted) / γd(in situ)

Vex = 2000 × 18.1 / 14.66

Vex = 2469.13 m³

So, the excavated volume of the soil is 2469.13 m³

3 0
4 years ago
A pinion and gear pair is used to transmit a power of 5000 W. The teeth numbers of pinion
tester [92]

Answer:

mark me as a brainleast

Explanation:

209781

6 0
3 years ago
What are the causes and solutions of social problems ?what are the causes and solutions of social problems ​
aksik [14]

Answer:

causes: unemployment, poverty,Lack of education,urbanization e.t.c

solutions:making people educated, giving people jobs

7 0
3 years ago
Air is drawn from the atmosphere into a turbomachine. At the exit, conditions are 500 kPa (gage) and 130oC. The exit speed is 10
finlep [7]

Answer:

P=- 88.41 KW

Negative sign indicates that power is given to the system.

Explanation:

Given that

P₂=500 KPa

T₂=130°C

V₂=100 m/s

mass flow rate ,m= 0.8 kg/s

Lets take inlet condition for air

T₁=25°C

P₁=100 KPa

V₁=0 m/s

We know that

Heat capacity for air Cp=1.005 KJ/kg.k

We know that for air change in enthalpy only depends only on temperature

Now from first law for open system

h_1+\dfrac{V_1^2}{2000}=h_2+\dfrac{V_2^2}{2000}+W

1.005\times 298+\dfrac{0^2}{2000}=1.005\times 403+\dfrac{100^2}{2000}+W

W=1.005\times 298-1.005\times 403-\dfrac{100^2}{2000}

W=-110.52 KJ/kg

Shaft power P = m .W

P = -110.52 x 0.8

P=- 88.41 KW

Negative sign indicates that power is given to the system.

 

3 0
4 years ago
In 2008 502 motorcyclists fire in Florida - an increase from<br> The number killed in 2004
faltersainse [42]
Is this a question ?
3 0
4 years ago
Other questions:
  • Refrigerant-134a is compressed from 2 bar, saturated vapor, to 10 bar, 90o C in a compressor operating at steady state. The mass
    11·1 answer
  • technician A says that in any circuit, electrical current takes the path of least resistance. technician B says that while this
    13·1 answer
  • Using the characteristics equation, determine the dynamic behavior of a PI controller with τI = 4 applied to a second order proc
    6·1 answer
  • Assume the average fuel flow rate at the peak torque speed (1500 rpm) is 15kg/hr for a sixcylinder four-stroke diesel engine und
    11·1 answer
  • The Republican National Committee publishes a monthly digest of information for Republicans called .
    15·1 answer
  • Were you surprised by the “pie data”? Is it true for you, your family, and your friends? Why or why not?
    13·2 answers
  • Identify the part of the direct current motor​
    9·1 answer
  • The insulation resistance of a motor operated by an electronic drive is to be tested using a megger. What precaution should you
    5·1 answer
  • X − 3y − 8z = −10 2x + 5y + 6z = 13 3x + 2y − 2z = 3
    12·1 answer
  • Which type of astm c150 standard portland cement is best suited for a concrete where minimal total heat evolution and minimal ra
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!