{"id":2244,"date":"2017-06-12T08:20:35","date_gmt":"2017-06-12T08:20:35","guid":{"rendered":"https:\/\/www.testingdocs.com\/questions\/?p=2244"},"modified":"2021-03-21T07:05:09","modified_gmt":"2021-03-21T07:05:09","slug":"java-decrement-operator","status":"publish","type":"post","link":"https:\/\/www.testingdocs.com\/questions\/java-decrement-operator\/","title":{"rendered":"Java Decrement Operator"},"content":{"rendered":"<h3>Program Description<\/h3>\n<p>Write a java program to demo the decrement operator. We will look at a simple java program using the decrement operator. We will have a look at the postfix-decrement operation and prefix-decrement operation in the program.<\/p>\n<h3>Syntax<\/h3>\n<p><strong>&#8211; &#8211; Decrement operator: decrements the variable value by 1<\/strong><\/p>\n<h3>Postfix decrement<\/h3>\n<p>b=a&#8211;;<\/p>\n<h3>Prefix decrement<\/h3>\n<p>b= &#8211;a;<\/p>\n<h3>Java Program<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">\/\/ DecrementOperatorDemo.java program\r\npublic class DecrementOperatorDemo {\r\n\r\n  public static void main(String[] args) {\r\n    int a = 4; \r\n    a--; \r\n\r\n    \/\/print the variable\r\n    System.out.println(\"a after Decrement should print 3= \" + a);\r\n\r\n    int b;\r\n    b= a--;\/\/ a is assigned to b and then decremented\r\n\r\n    \/\/print the variable\r\n    System.out.println(\"b after post decrement should print 3= \" + b);\r\n    \/\/ a value is 2 now\r\n    b= --a;\/\/ a value is decremented and assigned to b\r\n    \/\/print the variable\r\n    System.out.println(\"b after pre decrement should print 1= \" + b);\r\n  } \r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<h3>Program Output<\/h3>\n<p>a after Decrement should print 3= 3<br \/>\nb after post decrement should print 3= 3<br \/>\nb after pre decrement should print 1= 1<\/p>\n<h3>Screenshot<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2358\" src=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Decrement-Operator-Demo-Java-Program.png\" alt=\"Decrement operator\" width=\"1712\" height=\"1030\" title=\"\" srcset=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Decrement-Operator-Demo-Java-Program.png 1712w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Decrement-Operator-Demo-Java-Program-300x180.png 300w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Decrement-Operator-Demo-Java-Program-1024x616.png 1024w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Decrement-Operator-Demo-Java-Program-768x462.png 768w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Decrement-Operator-Demo-Java-Program-1536x924.png 1536w\" sizes=\"auto, (max-width: 1712px) 100vw, 1712px\" \/><\/p>\n<h3><\/h3>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<!--themify_builder_content-->\n<div id=\"themify_builder_content-2244\" data-postid=\"2244\" class=\"themify_builder_content themify_builder_content-2244 themify_builder tf_clear\">\n    <\/div>\n<!--\/themify_builder_content-->\n","protected":false},"excerpt":{"rendered":"<p>Program Description Write a java program to demo the decrement operator. We will look at a simple java program using the decrement operator. We will have a look at the postfix-decrement operation and prefix-decrement operation in the program. Syntax &#8211; &#8211; Decrement operator: decrements the variable value by 1 Postfix decrement b=a&#8211;; Prefix decrement b= [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2244","post","type-post","status-publish","format-standard","hentry","category-automation","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\/2244","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=2244"}],"version-history":[{"count":3,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/2244\/revisions"}],"predecessor-version":[{"id":19752,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/2244\/revisions\/19752"}],"wp:attachment":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/media?parent=2244"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/categories?post=2244"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/tags?post=2244"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}