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
LINKS GET BODIED ON SITE! RAWR
bulgar [2K]

Answer:

False

Explanation:

MRK ME BRAINLIEST PLZZZZZZZZZZZZZZZZZZ

7 0
3 years ago
What is made in heaven?​
kramer

Answer:

Babies come from heaven didn't you know?

3 0
2 years ago
Analyse what effect the building of an airport may have on the decision of how to use an area of land nearby. (6)​
Sonja [21]
An effect might be a customer not wanting to buy it specifically because it’s by an airport, or maybe the customer wants to buy it because it’s right next to the airport, and a lot of people go to the airport so therefore they might go to the building next to the airport.
5 0
3 years ago
1. A rectangular fish tank measures 1.5 meters by 2 meters by 20 cm. When it is filled with water, how many kilograms will the w
chubhunter [2.5K]
20kg I’m pretty sure
7 0
3 years ago
________ delivers the precise number of parts to be assembled into a finished product at precisely the right time.
Roman55 [17]

Answer:

JIT

Explanation:

JIT stands for just-in-time

6 0
2 years ago
Other questions:
  • A(n)___ branch circuit supplies two or more receptacles or outlets for lighting and appliances
    10·1 answer
  • Witch truck company is better.<br><br> Ram <br> Ford <br> Toyoda<br> GMC
    5·2 answers
  • A civil engineer is asked to design a curved section of roadway that meets the following conditions: With ice on the road, when
    13·1 answer
  • You are an engineer at company XYZ, and you are dealing with the need to determine the maximum load you can apply to a set of bo
    13·1 answer
  • Nitrogen enters a steady-flow heat exchanger at 150 kPa, 10°C, and 100 m/s, and it receives heat as it flows through it. Nitroge
    15·1 answer
  • A liquid phase chemical reaction (A → B) takes place in a well-stirred tank. The concentration of compound A in the feed is CA0
    9·1 answer
  • El tiempo hasta que falle un sistema informático sigue una distribución Exponencial con media de 600hs. (Utilice 3 decimales par
    13·1 answer
  • I need a thesis statement about Engineers as Leaders.
    11·1 answer
  • Uestion 10
    12·1 answer
  • What are the materials and tools used to build a headgear?​
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!