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
Describe carbonation as it applies to the four-stroke engine.
valentinak56 [21]
Carbonation is more of a healer to the engine
5 0
3 years ago
Read 2 more answers
What is the biggest expectation when engineers test out designs?
forsale [732]
The answer is B because it could be feasible but it’s not a need it and you got a time frame but it’s not a requirement and it doesn’t have to be unique.
6 0
4 years ago
Read 2 more answers
Electric current originates from which part of an atom? *
yanalaym [24]

Answer: Electric current originates from positively charged protons negatively charged electrons of an atom.

Explanation:

The movement of ions (positive or negative) from one point to another is called electric current.

An atom has three sub-atomic particles. These are protons, neutrons and electrons.

Protons are positively charged, neutrons have no charge and electrons are negatively charged. Protons and neutrons reside inside the nucleus of an atom whereas electrons revolve around the nucleus.

So, protons and electrons are responsible for originating electric current form an atom as these are the charged particles.

Thus, we can conclude that electric current originates from positively charged protons negatively charged electrons of an atom.

3 0
3 years ago
The settlement of foundations is typically the result of three separate occurrences that take place in the soil which provides s
evablogger [386]

Answer:

The differences are listed below

Explanation:

The differences between consolidation and compaction are as follows:

In compaction the mechanical pressure is used to compress the soil. In consolidation, there is an application of stead pressure.

In compaction, there is a dynamic load by rapid mechanical methods like tamping, rolling, etc. In consolidation, there is static and sustained pressure applied for a long time.

In compaction, the soil volume is reduced by removing air from the void. In consolidation, the soil volume is reduced by squeezing out water from the pores.

Compaction is used for sandy soil, consolidation on the other hand, is used for clay soil.

7 0
3 years ago
Read 2 more answers
O que é necessário se conhecer para a determinação de uma força concentrada em um ponto?
skelet666 [1.2K]

Answer: its c

Explanation:

7 0
3 years ago
Other questions:
  • To be able to write an ss-domain equation for a circuit, use partial fraction decomposition to separate the terms in this equati
    12·1 answer
  • A 600-MW steam power plant, which is cooled by a nearby river, has a thermal efficiency of 54 percent. Determine the rate of hea
    9·1 answer
  • How do scientists and engineers use math to help them?
    14·1 answer
  • Draw an ERD for each of the following situations. (If you believe that you need to make additional assumptions, clearly state th
    15·1 answer
  • Digital leaders are people who __ others down a particular path.
    13·2 answers
  • You are designing the access control policies for a Web-based retail store. Customers access the store via the Web, browse produ
    11·1 answer
  • Who else hates this because i do
    12·2 answers
  • Based on your reading of the following, how does a triple save a fire department in time?
    5·1 answer
  • To find the quotient of 8 divided by 1/3, multiply 8 by?
    13·1 answer
  • The centre of the circumstancribing circle of a triangle can be found by using the
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!