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
A(n) ________ is a program that takes advantage of very low-level operating system functions to hide itself from all but the mos
Rufina [12.5K]

Answer:

a rootkit is a program that takes advantage of very low-level operating system functions

Explanation:

6 0
1 year ago
Computer works on the basis of?​
ASHA 777 [7]
Computer works on the Basis of multitasking.
6 0
2 years ago
You open a web page and log into your email. The traffic travels over many routers. What protocol will the routers use to determ
exis [7]

Answer:

Border Gateway Protocol is a protocol the routers use to determine the most optimal path to forward the traffic.

Explanation:

BGP is a path vector protocol which chooses the most optimal path. The protocol decides core routing decisions based on path, configuration and network.

This protocol gives all the notification about the status of the connection and router.

It is used to routing in an autonomous system and provides ways to measure the effectiveness of configuration.

6 0
2 years ago
Pls answer will give brainlest dont answer if you dont know Upload your 300-word essay containing the following: the definition
Rainbow [258]

Answer: oh hello human :) also PLEASE DONT KILL ME I’m answering this because the question was already answered already on another post

6 0
2 years ago
The domain in an email message tells you the
bezimeni [28]
The question is asking to choose among the following choices that state what would the domain in an email represents, base on my research, I would say that the answer would be letter B. location of the destination. I hope you are satisfied with my answer and feel free to ask for more 
8 0
3 years ago
Other questions:
  • . A register in a computer has a of bits. How many unique combinations can be stored in the register?
    5·1 answer
  • The jailbreak property that, if the user turns the device off and back on, the device will start up completely, and the kernel w
    15·1 answer
  • str1=”Good” str2=”Evening” Does the concatenation of the above two strings give back a new string or does it concatenate on the
    14·1 answer
  • C:\windows\system32\drivers\etc\protocol is an example of a file ________. select one:
    5·1 answer
  • Your textbook discussed a record store example where one user could perform a query to determine which recordings had a track le
    14·1 answer
  • What is TSM Hamlinz’s discord
    6·2 answers
  • All parking revenue comes from a home teams games? True or false
    5·1 answer
  • Write an enhanced for loop that multiplies all elements in an int[] array named factors, accumulating the result in a variable n
    11·1 answer
  • Which of these is NOT an input device?
    14·1 answer
  • Which workbook view is used most often in Excel?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!