{"id":1333,"date":"2022-03-03T06:55:24","date_gmt":"2022-03-03T06:55:24","guid":{"rendered":"https:\/\/mdr.foobrdigital.com\/?p=1333"},"modified":"2022-03-03T06:55:24","modified_gmt":"2022-03-03T06:55:24","slug":"swap-two-numbers","status":"publish","type":"post","link":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/2022\/03\/03\/swap-two-numbers\/","title":{"rendered":"Swap Two Numbers"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Swap two numbers using temporary variable<\/h2>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class SwapNumbers {\n\n    public static void main(String&#91;] args) {\n\n        float first = 1.20f, second = 2.45f;\n\n        System.out.println(\"--Before swap--\");\n        System.out.println(\"First number = \" + first);\n        System.out.println(\"Second number = \" + second);\n\n        \/\/ Value of first is assigned to temporary\n        float temporary = first;\n\n        \/\/ Value of second is assigned to first\n        first = second;\n\n        \/\/ Value of temporary (which contains the initial value of first) is assigned to second\n        second = temporary;\n\n        System.out.println(\"--After swap--\");\n        System.out.println(\"First number = \" + first);\n        System.out.println(\"Second number = \" + second);\n    }\n}<\/code><\/pre>\n\n\n\n<p><strong>Output<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><samp>--Before swap--\nFirst number = 1.2\nSecond number = 2.45\n--After swap--\nFirst number = 2.45\nSecond number = 1.2<\/samp><\/code><\/pre>\n\n\n\n<p>In the above program, two numbers&nbsp;<code>1.20f<\/code>&nbsp;and&nbsp;<code>2.45f<\/code>&nbsp;which are to be swapped are stored in variables:&nbsp;<var>first<\/var>&nbsp;and&nbsp;<var>second<\/var>&nbsp;respectively.<\/p>\n\n\n\n<p>The variables are printed before swapping using&nbsp;<code>println()<\/code>&nbsp;to see the results clearly after swapping is done.<\/p>\n\n\n\n<ul><li>First, the value of&nbsp;<var>first<\/var>&nbsp;is stored in variable&nbsp;<var>temporary<\/var>&nbsp;(<code>temporary = 1.20f<\/code>).<\/li><li>Then, value of&nbsp;<var>second<\/var>&nbsp;is stored in&nbsp;<var>first<\/var>&nbsp;(<code>first = 2.45f<\/code>).<\/li><li>And, finally value of&nbsp;<var>temporary<\/var>&nbsp;is stored in&nbsp;<var>second<\/var>&nbsp;(<code>second = 1.20f<\/code>).<\/li><\/ul>\n\n\n\n<p>This completes the swapping process and the variables are printed on the screen.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Swap two numbers using temporary variable Output: In the above program, two numbers&nbsp;1.20f&nbsp;and&nbsp;2.45f&nbsp;which are to be swapped are stored in variables:&nbsp;first&nbsp;and&nbsp;second&nbsp;respectively. The variables are printed before swapping using&nbsp;println()&nbsp;to see the results clearly after swapping is done. First, the value of&nbsp;first&nbsp;is stored in variable&nbsp;temporary&nbsp;(temporary = 1.20f). Then, value of&nbsp;second&nbsp;is stored in&nbsp;first&nbsp;(first = 2.45f). And, finally value [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[287],"tags":[],"_links":{"self":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/1333"}],"collection":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/comments?post=1333"}],"version-history":[{"count":0,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/1333\/revisions"}],"wp:attachment":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/media?parent=1333"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/categories?post=1333"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/tags?post=1333"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}