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
A 860 kΩ resistor has 34 μA of current. What is the supply voltage for this electric circuit?
Juliette [100K]

Explanation:

first changing kilo ohm to ohm

860000 = 860 kΩ

and change 34 micro ampare to ampare

34 μA=3.4×10^-5

recalling the equation V=I*R

V= 3.4×10^-5×860000

v=29.24

8 0
3 years ago
Read 2 more answers
A four-cylinder, four-stroke internal combustion engine operates at 2800 RPM. The processes within each cylinder are modeled as
Ulleksa [173]

Answer:

1) 287760.4 Hp

2) 18410899.5 kPa

Explanation:

The parameters given are;

p₁ = 14.7 lbf/in² = 101325.9 Pa

v₁ = 0.0196 ft³ = 0.00055501 m³

T₁ = 80°F = 299.8167 K

k = 1.4

Assumptions;

1) Air standard conditions are appropriate

2) There are negligible potential and kinetic energy changes

3) The air behaves as an ideal gas and has constant specific heat capacities of temperature and pressure

1) Process 1 to 2

Isentropic compression

T₂/T₁ = (v₁/v₂)^(1.4 - 1) = 10^0.4

p₂/p₁ = (v₁/v₂)^(1.4)

p₂ = p₁×10^0.4 =  101325.9*10^0.4 = 254519.153 Pa

T₂ = 299.8167*10^0.4 = 753.106 K

p₃ = 1080 lbf/in² = 7,446,338 Pa

Stage 2 to 3 is a constant volume process

p₃/T₃ = p₂/T₂

7,446,338/T₃ =   254519.153/753.106

T₃ = 7,446,338/(254519.153/753.106) = 22033.24 K

T₃/T₄ = (v₁/v₂)^(1.4 - 1) = 10^0.4

T₄ = 22033.24/(10^0.4) = 8771.59 K

The heat supplied, Q₁ = cv(T₃ - T₂) = 0.718*(22033.24 -753.106) = 15279.14 kJ

The heat rejected = cv(T₄ - T₁) = 0.718*(8771.59 - 299.8167) = 6082.73 kJ

W(net) = The heat supplied - The heat rejected = (15279.14 - 6082.73) = 9196.41 kJ

The power = W(net) × RPM/2*1/60 = 9196.41 * 2800/2*1/60 = 214582.9 kW

The power by the engine = 214582.9 kW = 287760.4 Hp

2) The mean effective pressure, MEP  = W(net)/(v₁ - v₂)

v₁ = 0.00055501 m³

v₁/v₂ = 10

v₂ = v₁/10 = 0.00055501/10 = 0.000055501

MEP  = 9196.41/(0.00055501 -  0.000055501) = 18410899.5 kPa

4 0
3 years ago
A hollow pipe is submerged in a stream of water so that the length of the pipe is parallel to the velocity of the water. If the
Arlecino [84]

Answer:

increases by a factor of 6.

Explanation:

Let us assume that the initial cross sectional area of the pipe is A m² while the initial velocity of the water is V m/s², hence the flow rate of the water is:

Initial flow rate = area * velocity = A * V = AV m³/s

The water speed doubles (2V m/s) and the cross-sectional area of the pipe triples (3A m²), hence the volume flow rate becomes:

Final flow rate = 2V * 3A = 6AV m³/s = 6 * initial flow rate

Hence, the volume flow rate of the water passing through it increases by a factor of 6.

8 0
3 years ago
Tech a says the higher the numarical gear ratio (4:1), the more torque that will be applied to the wheels. Tech b says that the
Zepler [3.9K]

Answer:

Tech A

Explanation:

The amount of energy required to apply the same force with a 1:1 ratio is divided into 4, so you can apply 4 times as much force than a 1:1 ratio. efficiency and speed come into play here, but assuming the machine powering the gear can run at a unlimited RPM, 4:1 will have more force and a slower output speed than a 2:1 ratio.

3 0
3 years ago
Read 2 more answers
The greater the force applied to an object, the _____ the change in speed or direction of the object.
storchak [24]

Answer:

b

Explanation:

8 0
3 years ago
Other questions:
  • #198. Moment of inertia about center of a segmented bar A bar of width is formed of three uniform segments with lengths and area
    7·1 answer
  • Pls help! 39 points!!
    5·2 answers
  • What are example for mantle
    5·1 answer
  • For an AC machine, what percentage of power is at the negative terminal?
    14·1 answer
  • PLEASE HELP WITH THIS ASAP! Thanks
    6·1 answer
  • Which of the following addresses future implications of design and process decisions?
    5·1 answer
  • Jack has been concerned about the rapidly changing green regulations in his state and his ability as a mechanical engineer to ke
    13·1 answer
  • What is a splitter gearbox​
    15·1 answer
  • During delivery of a 2023 ariya equipped with propilot assist 2. 0, what should you point out to your customers about the turn s
    12·1 answer
  • A machine has an efficiency of 15%. If the energy input is 300 joules, how much useful energy is generated?(1 point).
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!