Computer Science, asked by bhan61, 11 months ago

You are given three integer variables a, b and c. aand b already have some values stored in them.
c does not have any value stored in it.
Write the statements that swap the values in a and b.
Don’t write the Class & Main method, assume that they have already been defined.


bhan61: can anyone send it faster

Answers

Answered by nitish8089
2
algorithm.... or do like this:

// Scanner class is import so we just make object of them

Scanner sc=new Scanner(System.in);

int a=sc.nextInt();

int b=sc.nextInt();

int c;

System.out.println("value of a before swap is " + a +" value of b before swap "+ b);

// assign value of 'a 'in 'c' variable

c=a;

a=b;

// now 'a' assign the value of' b':

// now 'a' would have value of 'b' so from where we get value of 'a': just remember intially we assign value of 'a' in 'c 'so we use 'c 'in place of 'a'.

b=c;

// now 'b' had value of 'a': as i expressed above..

System.out.println("value of a after swap is " + a +" value of b after swap "+ b);

// all of the line is begin with double slash(//) is comment just for understanding not any use in program...

nitish8089: there is no thanks because if you give on writing answer it would show..
nitish8089: but really i apperciate and thankfull for your all the thanks which motivate me....
Similar questions