Computer Science, asked by vasanthij97, 1 year ago

ICSE

Class 10

Write a function that interchanges the value of two integers A and B without using any extra variable.

Answers

Answered by parthomsarwade
1

import java.util.*;

class exchange

{

public static void main(String args[])

{

Scanner sc=new Scanner(System.in);

System.out.println("enter 2 integers");

int a=sc.nextInt();

int b=sc.nextInt();

int i;

for(i=a;i is less than equal to a;I++)

{

b=a;

i=b;

}

System.out.println(a);

System.out.println(b);

}

}

I can't find the symbol of less than so


parthomsarwade: but i is for for loop
utkarshmishra9819: even if I is for loop
utkarshmishra9819: but look what you are using it for
utkarshmishra9819: you are using it to store the value of variable a thus i
utkarshmishra9819: using the same technique of using third variable veiled with loop
parthomsarwade: ok
vasanthij97: thank you so much both of you ^_^
parthomsarwade: But which text book u are using for computer cause i am also in clasd 10 icse
vasanthij97: u?
parthomsarwade: frank
Answered by utkarshmishra9819
2

Answer:

class prog{

void main(int a,int b)

{

a=a+b;

b=a-b;

a=a-b;

System.out.println(a+" "+b);

}

}

i haven't used any extra variable like the other who has answered.

please mark it as the brainliest answer.

Similar questions