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
Amanda and Tyler opened a business that specializes in shipping liquids, such as milk, juice, and water, in cylindrical containe
USPshnik [31]

Answer:

circleType.h

#ifndef circleType_H

#define circleType_H

class circleType

{

public:

void print();

void setRadius(double r);

//Function to set the radius.

//Postcondition: if (r >= 0) radius = r;

// otherwise radius = 0;

double getRadius();

//Function to return the radius.

//Postcondition: The value of radius is returned.

double area();

//Function to return the area of a circle.

//Postcondition: Area is calculated and returned.

double circumference();

//Function to return the circumference of a circle.

//Postcondition: Circumference is calculated and returned.

circleType(double r = 0);

//Constructor with a default parameter.

//Radius is set according to the parameter.

//The default value of the radius is 0.0;

//Postcondition: radius = r;

private:

double radius;

};

#endif

circleTypeImpl.cpp

#include <iostream>

#include "circleType.h"

using namespace std;

void circleType::print()

{

cout << "Radius = " << radius

<< ", area = " << area()

<< ", circumference = " << circumference();

}

void circleType::setRadius(double r)

{

if (r >= 0)

radius = r;

else

radius = 0;

}

double circleType::getRadius()

{

return radius;

}

double circleType::area()

{

return 3.1416 * radius * radius;

}

double circleType::circumference()

{

return 2 * 3.1416 * radius;

}

circleType::circleType(double r)

{

setRadius(r);

}

cylinderType.h

#ifndef cylinderType_H

#define cylinderType_H

#include "circleType.h"

class cylinderType: public circleType

{

public:

void print();

void setHeight(double);

double getHeight();

double volume();

double area();

//returns surface area

cylinderType(double = 0, double = 0);

private:

double height;

};

#endif

cylinderTypeImpl.cpp

#include <iostream>

#include "circleType.h"

#include "cylinderType.h"

using namespace std;

cylinderType::cylinderType(double r, double h)

: circleType(r)

{

setHeight(h);

}

void cylinderType::print()

{

cout << "Radius = " << getRadius()

<< ", height = " << height

<< ", surface area = " << area()

<< ", volume = " << volume();

}

void cylinderType::setHeight(double h)

{

if (h >= 0)

height = h;

else

height = 0;

}

double cylinderType::getHeight()

{

return height;

}

double cylinderType::area()

{

return 2 * 3.1416 * getRadius() * (getRadius() + height);

}

double cylinderType::volume()

{

return 3.1416 * getRadius() * getRadius() * height;

}

main.cpp

#include <iostream>

#include <iomanip>

using namespace std;

#include "cylinderType.h"

int main()

{

double radius,height;

double shippingCostPerLi,paintCost,shippingCost=0.0;

 

cout << fixed << showpoint;

cout << setprecision(2);

cout<<"Enter the radius :";

cin>>radius;

 

cout<<"Enter the Height of the cylinder :";

cin>>height;

 

 

cout<<"Enter the shipping cost per liter :$";

cin>>shippingCostPerLi;

 

 

//Creating an instance of CylinderType by passing the radius and height as arguments

cylinderType ct(radius,height);

 

double surfaceArea=ct.area();

double vol=ct.volume();

 

 

shippingCost+=vol*28.32*shippingCostPerLi;

 

char ch;

 

cout<<"Do you want the paint the container (y/n)?";

cin>>ch;

if(ch=='y' || ch=='Y')

{

cout<<"Enter the paint cost per sq foot :$";

cin>>paintCost;    

shippingCost+=surfaceArea*paintCost;    

}    

cout<<"Total Shipping Cost :$"<<shippingCost<<endl;

 

return 0;

}

3 0
3 years ago
An alloy is evaluated for potential creep deformation in a short-term laboratory experiment. The creep rate (ϵ˙) is found to be
cupoosta [38]

Answer:

Activation energy for creep in this temperature range is Q = 252.2 kJ/mol

Explanation:

To calculate the creep rate at a particular temperature

creep rate, \zeta_{\theta} = C \exp(\frac{-Q}{R \theta} )

Creep rate at 800⁰C, \zeta_{800} = C \exp(\frac{-Q}{R (800+273)} )

\zeta_{800} = C \exp(\frac{-Q}{1073R} )\\\zeta_{800} = 1 \% per hour =0.01\\

0.01 = C \exp(\frac{-Q}{1073R} ).........................(1)

Creep rate at 700⁰C

\zeta_{700} = C \exp(\frac{-Q}{R (700+273)} )

\zeta_{800} = C \exp(\frac{-Q}{973R} )\\\zeta_{800} = 5.5 * 10^{-2}  \% per hour =5.5 * 10^{-4}

5.5 * 10^{-4}  = C \exp(\frac{-Q}{1073R} ).................(2)

Divide equation (1) by equation (2)

\frac{0.01}{5.5 * 10^{-4} } = \exp[\frac{-Q}{1073R} -\frac{-Q}{973R} ]\\18.182= \exp[\frac{-Q}{1073R} +\frac{Q}{973R} ]\\R = 8.314\\18.182= \exp[\frac{-Q}{1073*8.314} +\frac{Q}{973*8.314} ]\\18.182= \exp[0.0000115 Q]\\

Take the natural log of both sides

ln 18.182= 0.0000115Q\\2.9004 = 0.0000115Q\\Q = 2.9004/0.0000115\\Q = 252211.49 J/mol\\Q = 252.2 kJ/mol

3 0
2 years ago
To put out a class D metal fire, you must _______ the fire.
gladu [14]

To put out a class D metal fire, you must smother the fire and eliminate the oxygen element in the fire.

<h3>What is a Class D fire?</h3>

A class D fire is a type of fire that cannot be extinguished by water. This is because adding water to it reacts with other elements in the fire intensifying the fire even more.

Smothering in this context involves adding a solution like carbon dioxide (CO2) into the fire, this results in a reduction of oxygen in the atmosphere surrounding the class D fire.

By so doing, smothering the fire eliminates the oxygen element in the fire, thereby extinguishing the fire.

You can learn more about extinguishing fires here https://brainly.in/question/760550

#SPJ1

7 0
2 years ago
What is the sun's degree angle in the sky in summer and in winter?
Vladimir [108]

Answer:

At the time of the summer or winter solstices, the Sun is 23.44° degrees above or below the horizon, respectively, irrespective of time of day.

Explanation:

6 0
2 years ago
Find the time-domain sinusoid for the following phasors:_________
sattari [20]

<u>Answer</u>:

a.  r(t) = 6.40 cos (ωt + 38.66°) units

b.  r(t) = 6.40 cos (ωt - 38.66°) units

c.  r(t) = 6.40 cos (ωt - 38.66°) units

d.  r(t) = 6.40 cos (ωt + 38.66°) units

<u>Explanation</u>:

To find the time-domain sinusoid for a phasor, given as a + bj, we follow the following steps:

(i) Convert the phasor to polar form. The polar form is written as;

r∠Ф

Where;

r = magnitude of the phasor = \sqrt{a^2 + b^2}

Ф = direction = tan⁻¹ (\frac{b}{a})

(ii) Use the magnitude (r) and direction (Φ) from the polar form to get the general form of the time-domain sinusoid (r(t)) as follows:

r(t) = r cos (ωt + Φ)

Where;

ω = angular frequency of the sinusoid

Φ = phase angle of the sinusoid

(a) 5 + j4

<em>(i) convert to polar form</em>

r = \sqrt{5^2 + 4^2}

r = \sqrt{25 + 16}

r = \sqrt{41}

r = 6.40

Φ = tan⁻¹ (\frac{4}{5})

Φ = tan⁻¹ (0.8)

Φ = 38.66°

5 + j4 = 6.40∠38.66°

(ii) <em>Use the magnitude (r) and direction (Φ) from the polar form to get the general form of the time-domain sinusoid</em>

r(t) = 6.40 cos (ωt + 38.66°)

(b) 5 - j4

<em>(i) convert to polar form</em>

r = \sqrt{5^2 + (-4)^2}

r = \sqrt{25 + 16}

r = \sqrt{41}

r = 6.40

Φ = tan⁻¹ (\frac{-4}{5})

Φ = tan⁻¹ (-0.8)

Φ = -38.66°

5 - j4 = 6.40∠-38.66°

(ii) <em>Use the magnitude (r) and direction (Φ) from the polar form to get the general form of the time-domain sinusoid</em>

r(t) = 6.40 cos (ωt - 38.66°)

(c) -5 + j4

<em>(i) convert to polar form</em>

r = \sqrt{(-5)^2 + 4^2}

r = \sqrt{25 + 16}

r = \sqrt{41}

r = 6.40

Φ = tan⁻¹ (\frac{4}{-5})

Φ = tan⁻¹ (-0.8)

Φ = -38.66°

-5 + j4 = 6.40∠-38.66°

(ii) <em>Use the magnitude (r) and direction (Φ) from the polar form to get the general form of the time-domain sinusoid</em>

r(t) = 6.40 cos (ωt - 38.66°)

(d) -5 - j4

<em>(i) convert to polar form</em>

r = \sqrt{(-5)^2 + (-4)^2}

r = \sqrt{25 + 16}

r = \sqrt{41}

r = 6.40

Φ = tan⁻¹ (\frac{-4}{-5})

Φ = tan⁻¹ (0.8)

Φ = 38.66°

-5 - j4 = 6.40∠38.66°

(ii) <em>Use the magnitude (r) and direction (Φ) from the polar form to get the general form of the time-domain sinusoid</em>

r(t) = 6.40 cos (ωt + 38.66°)

3 0
3 years ago
Other questions:
  • A pressure gage connected to a tank reads 50 psi at a location where the barometric reading is 29.1 inches Hg. Determine the abs
    6·1 answer
  • A rotating cup viscometer has an inner cylinder diameter of 2.00 in., and the gap between cups is 0.2 in. The inner cylinder len
    9·1 answer
  • Compute the estimated actual endurance limit for SAE 4130 WQT 1300 steel bar with a rectangular cross section of 20.0 mm by 60 m
    11·1 answer
  • The hot water needs of an office are met by heating tab water by a heat pump from 16 C to 50 C at an average rate of 0.2 kg/min.
    5·1 answer
  • What did the romans adopt from the Greek representation of the human art form
    15·1 answer
  • Energy that causes a transfer of heat between marterials
    13·1 answer
  • Which of the following is an example of seeking accreditation?
    7·1 answer
  • A string of ASCII characters has been converted to hexadecimal resulting in the following message: 4A EF 62 73 73 F4 E5 76 E5 Of
    6·1 answer
  • Tony works as a Sorter in a processing factory. Which qualifications does he most likely have?
    10·2 answers
  • I need the answer please
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!