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
Sloan [31]
3 years ago
14

There are two String variables, s1 and s2, that have already been declared and initialized. Write some code that exchanges their

values. Declare any other variables as necessary.
Computers and Technology
2 answers:
Ivan3 years ago
8 0

Answer:

//here is code in java.

import java.util.*;

class Solution

{

// main method of class

public static void main (String[] args) throws java.lang.Exception

{

   try{

    // declare an initialize first string variables

     String st1="hello";

     // declare an initialize first string variables

     String st2="world";

     // create another string variable

    String st3;

    // exchange the value of both string variables

    st3=st1;

    st1=st2;

    st2=st3;

    System.out.println("value of first String after exchange: "+st1);

    System.out.println("value of second String after exchange: "+st2);

   }catch(Exception ex){

       return;}

}

}

Explanation:

declare and initialize two string variables.Create another string variable "st3". first assign value of "st1" to "st3" after then value of "st2" to "st1" and then  assign value of "st3" to "st2". This will exchange the values of both the string.

Output:

value of first String after exchange: world

value of second String after exchange: hello

Lunna [17]3 years ago
5 0

Answer:

The following are the code

string s1="san";

string s2="ran";

string temp; // other variable

temp=s1;// statement 1

s1=s2;// statement 2

s2=temp;//statement 3

Explanation:

In this code we declared two string s1 , s2 and initialized them after that we declared an extra variable temp .

The statement 1  temp=s1   means that temp will store the value of s1 i.e "san". so temp="san";

The second statement 2  s1=s2   means that s1 will store the value of s2

i.e s1="ran";

The third statement 3 s2=temp means that s2 will store the value of temp.

i.e s2="san"

we see that s1 and s2 will exchange their value

Following are the code in c++

#include <iostream> // header file

#include<string>

using namespace std;

int main()// main function

{

string s1="san";

string s2="ran";

string temp;

cout<<"before exchange:"<<s1<<s2<<endl; // display before exchanging the value

temp=s1;

s1=s2;

s2=temp;

cout<<"after exchange:"<<s1<<s2<<endl;// display after exchanging the value

return 0;

}

Output:

before exchange:sanran

after exchange:ransan

You might be interested in
What is a function in Microsoft Excel?
uranmaximum [27]

Answer:

Tool for creating charts.

Explanation:

MS excel is clearly used for designing charts and spreadsheet in our daily life.

4 0
3 years ago
How can social media be useful for brand awareness ?
shutvik [7]
It lets them reach out to people on that platform that can advertise their products
4 0
3 years ago
A serial schedule:
Lina20 [59]

Answer:

B)

Explanation:

Is alwayd sorted sequentially in aceding order by transaction ID

6 0
3 years ago
Discuss five domains of Instructional technology​
Effectus [21]

Answer:

Design, Development, Utilization, Management, and Evaluation.

7 0
3 years ago
The system cannot contact a domain controller to service the authentication request
slega [8]

Answer:  The correct answer is :  If it is not a DNS problem you can try to remove them from the domain by placing them in a workgroup, restart, then delete the computer trail in A / D Users & Computers, then re-enroll them in the domain and move them from the default location to their proper place in the A / D structure.

6 0
3 years ago
Other questions:
  • You have found an old dusty computer in your basement that you can identify as an original IBM PC. You ask your friend if he kno
    15·1 answer
  • Which statement best describes a transition in PowerPoint?
    12·1 answer
  • Which of these statements most accurately describes cookies?They have the capability to execute malicious software.Each cookie f
    12·1 answer
  • Which step of the laser printer imaging process requires troubleshooting if a printer produces ghost images on output pages?
    13·1 answer
  • What file does a aac run under
    11·1 answer
  • To use a macro, a user must first <br> ____ a macro and then <br> ____the macro.
    8·1 answer
  • Sonja is writing a program to compare two numbers and print the larger number. Which of these should be used?
    6·1 answer
  • What do you think is the importance of Science Technology and Society​
    8·1 answer
  • For her presentation on Italy, Matilda used a red background with light green text. When her friend critiqued her presentation,
    12·1 answer
  • What is a good theme statement for the short Pixar film "bao"?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!