{"id":2286,"date":"2017-06-12T06:53:04","date_gmt":"2017-06-12T06:53:04","guid":{"rendered":"https:\/\/www.testingdocs.com\/questions\/?p=2286"},"modified":"2021-03-21T07:06:01","modified_gmt":"2021-03-21T07:06:01","slug":"increment-operator","status":"publish","type":"post","link":"https:\/\/www.testingdocs.com\/questions\/increment-operator\/","title":{"rendered":"Java program for ++ Increment Operator"},"content":{"rendered":"<h3>Introduction<\/h3>\n<p>In this post, we will discuss the Increment Operator in java language. We will look at some simple java program using the operator. We will have a look at the postfix-increment operation and prefix-increment operation in the program.<\/p>\n<h3>Syntax<\/h3>\n<p><strong>++ Increment operator: increments a value by 1<\/strong><\/p>\n<h3>Postfix increment<\/h3>\n<p>b = a++;<\/p>\n<p>&nbsp;<\/p>\n<h3>Prefix increment<\/h3>\n<p>b = ++a;<\/p>\n<h3>Java Program<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">\/\/ IncrementOperatorDemo.java program\r\npublic class IncrementOperatorDemo {\r\n\r\n  public static void main(String[] args) {\r\n    int a = 1; \r\n    a++; \r\n\r\n    \/\/print the variable\r\n    System.out.println(\"a after increment should print 2= \" + a);\r\n\r\n    int b;\r\n    b= a++;\/\/ a is assigned to b and then incremented\r\n\r\n    \/\/print the variable\r\n    System.out.println(\"b after post increment should print 2= \" + b);\r\n    \/\/ a value is 3 now\r\n    b= ++a;\/\/ a value is incremented and assigned to b\r\n    \/\/print the variable\r\n    System.out.println(\"b after pre increment should print 4= \" + b);\r\n  } \r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>In the program, we have initialized two variables a &amp; b and then increment them using the operator. We print the post incremented ++ variables a &amp; b.<\/p>\n<h3>Program Output<\/h3>\n<p>a after increment should print 2= 2<br \/>\nb after post increment should print 2= 2<br \/>\nb after pre increment should print 4= 4<\/p>\n<h3>Screenshot<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2350\" src=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Increment-Operator-Demo.png\" alt=\"Increment Operator Demo\" width=\"1729\" height=\"1001\" title=\"\" srcset=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Increment-Operator-Demo.png 1729w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Increment-Operator-Demo-300x174.png 300w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Increment-Operator-Demo-1024x593.png 1024w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Increment-Operator-Demo-768x445.png 768w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Increment-Operator-Demo-1536x889.png 1536w\" sizes=\"auto, (max-width: 1729px) 100vw, 1729px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<!--themify_builder_content-->\n<div id=\"themify_builder_content-2286\" data-postid=\"2286\" class=\"themify_builder_content themify_builder_content-2286 themify_builder tf_clear\">\n    <\/div>\n<!--\/themify_builder_content-->\n","protected":false},"excerpt":{"rendered":"<p>Introduction In this post, we will discuss the Increment Operator in java language. We will look at some simple java program using the operator. We will have a look at the postfix-increment operation and prefix-increment operation in the program. Syntax ++ Increment operator: increments a value by 1 Postfix increment b = a++; &nbsp; Prefix [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-2286","post","type-post","status-publish","format-standard","hentry","category-java-programs","has-post-title","has-post-date","has-post-category","has-post-tag","has-post-comment","has-post-author",""],"_links":{"self":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/2286","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/comments?post=2286"}],"version-history":[{"count":3,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/2286\/revisions"}],"predecessor-version":[{"id":19753,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/2286\/revisions\/19753"}],"wp:attachment":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/media?parent=2286"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/categories?post=2286"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/tags?post=2286"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}