Skip to Content

Swap Numbers Java Example

  • strict warning: Non-static method view::load() should not be called statically in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/views.module on line 906.
  • strict warning: Declaration of views_handler_argument::init() should be compatible with views_handler::init(&$view, $options) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_argument.inc on line 0.
  • strict warning: Declaration of views_handler_filter::options_validate() should be compatible with views_handler::options_validate($form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_filter.inc on line 0.
  • strict warning: Declaration of views_handler_filter::options_submit() should be compatible with views_handler::options_submit($form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_filter.inc on line 0.
  • strict warning: Declaration of views_handler_filter_boolean_operator::value_validate() should be compatible with views_handler_filter::value_validate($form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_filter_boolean_operator.inc on line 0.
  • strict warning: Declaration of views_plugin_style_default::options() should be compatible with views_object::options() in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/plugins/views_plugin_style_default.inc on line 0.
  • strict warning: Declaration of views_plugin_row::options_validate() should be compatible with views_plugin::options_validate(&$form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/plugins/views_plugin_row.inc on line 0.
  • strict warning: Declaration of views_plugin_row::options_submit() should be compatible with views_plugin::options_submit(&$form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/plugins/views_plugin_row.inc on line 0.

  1. /*
  2.         Swap Numbers Java Example
  3.         This Swap Numbers Java Example shows how to
  4.         swap value of two numbers using java.
  5. */
  6.  
  7. public class SwapElementsExample {
  8.  
  9.         public static void main(String[] args) {
  10.                
  11.                 int num1 = 10;
  12.                 int num2 = 20;
  13.                
  14.                 System.out.println("Before Swapping");
  15.                 System.out.println("Value of num1 is :" + num1);
  16.                 System.out.println("Value of num2 is :" +num2);
  17.                
  18.                 //swap the value
  19.                 swap(num1, num2);
  20.         }
  21.  
  22.         private static void swap(int num1, int num2) {
  23.                
  24.                 int temp = num1;
  25.                 num1 = num2;
  26.                 num2 = temp;
  27.                
  28.                 System.out.println("After Swapping");
  29.                 System.out.println("Value of num1 is :" + num1);
  30.                 System.out.println("Value of num2 is :" +num2);
  31.                
  32.         }
  33. }
  34.  
  35. /*
  36. Output of Swap Numbers example would be
  37. Before Swapping
  38. Value of num1 is :10
  39. Value of num2 is :20
  40. After Swapping
  41. Value of num1 is :20
  42. Value of num2 is :10
  43. */