SHARE
TWEET

Untitled

a guest May 23rd, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. namespace example {
  2.     public class Swap {
  3.         public static int num1;
  4.         public static int num2;
  5.  
  6.         public static void Main() {
  7.  
  8.             //get two inputs
  9.             while(!int.TryParse(System.Console.ReadLine(), out num1)){
  10.                 System.Console.WriteLine("That was invalid input, enter a integer.");
  11.             }
  12.             while(!int.TryParse(System.Console.ReadLine(), out num2)){
  13.                 System.Console.WriteLine("That was invalid input, enter a integer.");
  14.             }
  15.            
  16.            
  17.             System.Console.WriteLine("1st Number: " + num1 + ", 2nd Number : " + num2);
  18.            
  19.             //swap values
  20.             swapValues(ref num1, ref num2);
  21.            
  22.             System.Console.WriteLine("The value of the 1st variable: " + num1);
  23.             System.Console.WriteLine("The value of the 2nd variable: " + num2);
  24.         }
  25.        
  26.  
  27.         //get two integer as parameter and swap them
  28.         public static void swapValues(ref int num1, ref int num2) {
  29.  
  30.             num1 = num1 + num2;
  31.             num2 = num1 - num2;
  32.             num1 = num1 - num2;
  33.  
  34.         }
  35.     }
  36. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top