Computer Science, asked by Anonymous, 5 months ago

Write a program in java to enter two
numbers and swap them using third variable.
Board- ICSE
Class- 9​

Answers

Answered by livingston42
1

Answer:

the history of human is closely related to the state-of-the-art contains 6 logical logical and biological records of historical times in its upper layer they are important for reconstructing this tree of the earth and various living organism the Fossil of the human ancestors are embedded in the earth's layer value anthropologists and also reduced the soil and rock layers of the earth and extract the evidence about human ancestors this players and the fossils are scientifically dated to study the various status in human evolution and priest through the gather evidence they attempt to understand the evolution of humanistic and development season chronological order

Answered by sngd008
0

Answer:

Program to swap two numbers

This program is to swap/exchange two numbers by using a variable.

For example:

Numbers to swap: 11 and 12

Let x= 11, y= 12

Swapping Logic:

t=x= 11

x =y =12

y =t =11

After swapping:

x= 12, y = 11

Algorithm

STEP 1: START

STEP 2: DEFINE x, y, t

STEP 3: ENTER x, y

STEP 4: PRINT x, y

STEP 5: t = x

STEP 6: x= y

STEP 7: y= t

STEP 8: PRINT x, y

STEP 9: END

Java Program

import java.util.*;

class Swap_With {

public static void main(String[] args) {

int x, y, t;// x and y are to swap

Scanner sc = new Scanner(System.in);

System.out.println("Enter the value of X and Y");

x = sc.nextInt();

y = sc.nextInt();

System.out.println("before swapping numbers: "+x +" "+ y);

/*swapping */

t = x;

x = y;

y = t;

System.out.println("After swapping: "+x +" " + y);

System.out.println( );

}

}

Output:

Enter the value of X and Y

2

3

before swapping numbers: 2 3

After swapping: 3 2

C Program

#include <stdio.h>

int main()

{

int x, y, t;// x and y are the swapping variables and t is another variable

printf("Enter the value of X and Y\n");

scanf("%d%d", &x, &y);

printf("before swapping numbers: %d %d\n",x,y);

/*swapping*/

t = x;

x = y;

y = t;

printf("After swapping: %d %d",x,y);

return 0;

}

Output:

Enter the value of X and Y

29

39

before swapping numbers: 29 39

After swapping: 39 29

Python Program

x = int(input("Enter the value of x?"))

y = int(input("Enter the value of y?"))

print("before swapping numbers: %d %d\n" %(x,y))

#swapping#

temp = x

x = y

y = temp

print("After swapping: %d %d\n"%(x,y))

Output:

Enter the value of X? 87

Enter the value of Y? 43

before swapping numbers: 87 43

After swapping: 43 87

PHP Program

<?php

echo "Enter the value of x";

$x = readline();

echo "Enter the value of y";

$y = readline();

echo "before swapping numbers: ";

echo $x;

echo " ";

echo $y;

echo "\n";

/*swapping*/

$temp = $x;

$x = $y;

$y = $temp;

echo "After swapping ";

echo $x;

echo " ";

echo $y;

?>

Output:

Enter the value of x

33

Enter the value of Y

22

before swapping numbers: 33 22

After swapping 22 33

C# Program

using System;

public class Swap

{

public static void Main()

{

Console.WriteLine("Enter the value of x and y");

int x=Convert.ToInt32(Console.ReadLine());

int y = Convert.ToInt32(Console.ReadLine());

int temp;

Console.WriteLine("before swapping numbers: "+x +" "+ y);

/*swapping*/

temp = x;

x = y;

y = temp;

Console.WriteLine("After swapping: "+x +" " + y);

}}

Output:Enter the value of x and y

65

54

before swapping numbers: 65 54

After swapping: 54 65

Similar questions