Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace example {
- public class Swap {
- public static int num1;
- public static int num2;
- public static void Main() {
- //get two inputs
- while(!int.TryParse(System.Console.ReadLine(), out num1)){
- System.Console.WriteLine("That was invalid input, enter a integer.");
- }
- while(!int.TryParse(System.Console.ReadLine(), out num2)){
- System.Console.WriteLine("That was invalid input, enter a integer.");
- }
- System.Console.WriteLine("1st Number: " + num1 + ", 2nd Number : " + num2);
- //swap values
- swapValues(ref num1, ref num2);
- System.Console.WriteLine("The value of the 1st variable: " + num1);
- System.Console.WriteLine("The value of the 2nd variable: " + num2);
- }
- //get two integer as parameter and swap them
- public static void swapValues(ref int num1, ref int num2) {
- num1 = num1 + num2;
- num2 = num1 - num2;
- num1 = num1 - num2;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement