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
Ierofanga [76]
3 years ago
5

Write a Java program that generates a new string by concatenating the reversed substrings of even indexes and odd indexes separa

tely from a given string.

Computers and Technology
1 answer:
salantis [7]3 years ago
8 0

Answer:

/ReversedEvenOddString.java

import java.util.Scanner;

public class ReversedEvenOddString {

   public static void main(String[] args) {

       Scanner sc = new Scanner(System.in);

       String s = sc.nextLine();

       String evens = "";

       String odds = "";

       for(int i = s.length()-1;i>=0;i--){

           if(i%2==1){

               odds += s.charAt(i);

           }

           else{

               evens += s.charAt(i);

           }

       }

       String res;

       if(s.length()%2==1){

           res = evens+odds;

       }

       else{

           res = odds+evens;

       }

       System.out.println(res);

   }

}

You might be interested in
Write a Twitter class that sets the Twitter user first (who is to be followed) and lets the client add up to 5 followers, which
Rzqust [24]

Answer:

Twitter.h

========

#ifndef Twitter_h

#define Twitter_h

#include <iostream>

using std::string;

using std::cout;

using std::endl;

template <typename T>

class Twitter

{

private:

string name;

T followers[5];

int numFollowers;

public:

Twitter(string n);

bool AddFollower(T follower);

bool RemoveFollower(T follower);

void PrintFollowers();

};

template <typename T>

Twitter<T>::Twitter(string n)

{

name = n;

numFollowers = 0;

}

template <typename T>

bool Twitter<T>::AddFollower(T follower)

{

if(numFollowers < 5)

{

followers[numFollowers] = follower;

numFollowers++;

return true;

}

else

return false;

}

template <typename T>

bool Twitter<T>::RemoveFollower(T follower)

{

int index;

bool found = false;

for(index = 0; index < numFollowers; index++)

{

if(followers[index] == follower)

{

found = true;

break;

}

}

if(found)

{

//shift all other followers after the one to be removed to one position left

for(++index; index < numFollowers; ++index)

{

followers[index-1] = followers[index];

}

numFollowers--;

return true;

}

else

return false;

}

template <typename T>

void Twitter<T>::PrintFollowers()

{

cout << "Followers for " << name << endl;

for(int i = 0; i < numFollowers; i++)

cout << followers[i] << endl;

 

cout << "------" << endl << endl;

}

#endif /* Twitter_h */

main.cpp

=========

#include "Twitter.h"

#include <iostream>

using namespace std;

struct Profile {

string userName;

int age;

string state;

};

 

ostream& operator << (ostream & output, Profile p) {

output << p.userName;

return output;

}

bool operator == (const Profile &p1, const Profile p2)

{

return p1.userName == p2.userName;

}

int main()

{

Twitter<string> t1("John");

Twitter<Profile> t2("Bob");

 

cout << "Adding followers to John" << endl;

t1.AddFollower("Bill");

t1.AddFollower("Jack");

t1.PrintFollowers();

 

Profile p1 = {"Alice", 20, "Alaska"};

Profile p2 = {"Janet", 22, "California"};

Profile p3 = {"Jim", 20, "Texas"};

 

cout << "Adding follower profiles to Bob" << endl;

t2.AddFollower(p1);

t2.AddFollower(p2);

t2.AddFollower(p3);

t2.PrintFollowers();

 

cout << "Removing Bill from John" << endl;

t1.RemoveFollower("Bill");

 

cout << "Removing Janet's profile from Bob" << endl << endl;

t2.RemoveFollower(p2);

 

t1.PrintFollowers();

t2.PrintFollowers();

 

 

 

}

output

-======

Adding followers to John

Followers for John

Bill

Jack

------

Adding follower profiles to Bob

Followers for Bob

Alice

Janet

Jim

------

Removing Bill from John

Removing Janet's profile from Bob

Followers for John

Jack

------

Followers for Bob

Alice

Jim

------

Explanation:

4 0
3 years ago
Julio is the department head for his company's customer service department. His staff has complained that they spend countless h
shusha [124]
It's answer A. blog (you're gonna need it).
6 0
3 years ago
Read 2 more answers
Ew<br>subject: Computer<br>11101÷101<br> binary operations<br>​
lions [1.4K]
11101 / 101 = 109.9
5 0
2 years ago
Compress<br> 00eb:0000:0000:0000:d8c1:0946:0272:879<br> IPV6 Address
ikadub [295]

Answer:

Compress

00eb:0000:0000:0000:d8c1:0946:0272:879

IPV6 Addres

Explanation:

3 0
3 years ago
A company is looking for an employee to design and test connections in its
kolbaska11 [484]

The employee that design and test connections in its computer systems is in the computer architecture field.

<h3>What is design and test connections?</h3>

This is known to be a field in computer system where system engineers makes a lot of computer designs and also involve in testing of connections such as internet connections, etc.

Note that The employee that design and test connections in its computer systems is in the computer architecture field and they are known to be Computer software engineers

Learn more about  Computer jobs from

brainly.com/question/24588527

#SPJ1

8 0
1 year ago
Other questions:
  • Which of the following characters at the beginning of a cell signifies to Excel that it should perform a calculation for the val
    13·1 answer
  • PLEASE HELP!!!!! David has gone to the Niagara Falls with his camera. He wants to click photos of the people around him and also
    11·2 answers
  • 5. The stage of engine operation when both the intake and exhaust valves are closed is the _______ stage.
    5·1 answer
  • Although highly accurate navigational information from the GPS constellation is exploitable by adversary forces, it is unlikely
    5·1 answer
  • Whitch action should a user take to ensure that formatting is applied to a row? A. use the ctrl+a keys. B. highlight the whole t
    11·1 answer
  • All computers perform disk optimization utilizing the same software.<br><br> true <br> false
    11·1 answer
  • The stack pop operation
    10·1 answer
  • How to use repl.it css
    7·1 answer
  • If I got a monitor and kept my garbage laptop could I play games on max graphics?
    13·1 answer
  • What will be the result from running the following program?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!