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
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...
// 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...
Similar questions
English,
7 months ago
Computer Science,
7 months ago
World Languages,
1 year ago
Science,
1 year ago
Biology,
1 year ago
English,
1 year ago