Java Program To Swap Two numbers With Third Variable In Java | Java Practice Programs| Code Bode

Published: 15 June 2020
on channel: CodeBode
219
1

#swapnumbers #javatutorial #javaprograms

Hi Guyz,
In This Video We will learn how to swap two numbers in java with a third variable.

import java.util.Scanner;

public class NumberSwap {

public static void main(String[] args) {
// Swap two numbers using third variable
// 1. Take two input variables
// 2. Take a temp variable
// 3. assign number1 to temp
// 4. assign number2 to number1
// 5. assign temp to number2
// 6. Print two numbers

Scanner sc = new Scanner(System.in);
System.out.println("Please enter number 1");
int number1=sc.nextInt(); //10
System.out.println("Please enter number 2");
int number2=sc.nextInt(); //20
int temp;

temp=number1; //10
number1=number2; //20
number2=temp; //10

System.out.println("Number 1 :" +number1);
System.out.println("Number 2: "+number2);

}

}

Other Playlist :

Eclipse Tutorial :
   • Eclipse Tutorial  
HTML Tutorial :
   • Playlist  
Java Learning Path :


HAPPY LEARNING!


On this page of the site you can watch the video online Java Program To Swap Two numbers With Third Variable In Java | Java Practice Programs| Code Bode with a duration of hours minute second in good quality, which was uploaded by the user CodeBode 15 June 2020, share the link with friends and acquaintances, this video has already been watched 219 times on youtube and it was liked by 1 viewers. Enjoy your viewing!