{"id":2079,"date":"2018-05-26T06:56:00","date_gmt":"2018-05-26T06:56:00","guid":{"rendered":"https:\/\/www.testingdocs.com\/questions\/?p=2079"},"modified":"2024-08-09T09:04:26","modified_gmt":"2024-08-09T09:04:26","slug":"java-program-to-read-an-integer","status":"publish","type":"post","link":"https:\/\/www.testingdocs.com\/questions\/java-program-to-read-an-integer\/","title":{"rendered":"Java program to read an integer"},"content":{"rendered":"<h2>Program Description<\/h2>\r\n<p>Write a java program to read an integer entered by user. <strong>nextInt()<\/strong> method of the <strong>Scanner<\/strong> class will read the user input integer from the Standard input ( <strong>System.in<\/strong>) . We will declare a variable to hold the integer in our Java program.<\/p>\r\n<p>&nbsp;<\/p>\r\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2147\" src=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Read-an-Integer-Java-Program.png\" alt=\"\" width=\"1682\" height=\"879\" title=\"\" srcset=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Read-an-Integer-Java-Program.png 1682w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Read-an-Integer-Java-Program-300x157.png 300w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Read-an-Integer-Java-Program-1024x535.png 1024w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Read-an-Integer-Java-Program-768x401.png 768w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Read-an-Integer-Java-Program-1536x803.png 1536w\" sizes=\"auto, (max-width: 1682px) 100vw, 1682px\" \/><\/p>\r\n<h3>Java Program<\/h3>\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import java.util.Scanner;\r\n\/***********************************************************\r\n * IntegerDemo.java\r\n * @program : Java program to read an integer entered by user\r\n * @web : www.testingdocs.com\r\n * @version : 1.0\r\n ************************************************************\/ \r\npublic class IntegerDemo {\r\n\r\n  public static void main(String[] args) {\r\n\r\n    \/* This reads the input provided by user\r\n     * using keyboard\r\n     *\/\r\n    Scanner scan = new Scanner(System.in);\r\n    System.out.print(\"Enter any number: \");\r\n\r\n    \/\/ This method reads the number provided using keyboard\r\n    int num = scan.nextInt();\r\n\r\n    \/\/ Closing Scanner after the use\r\n    scan.close();\r\n\r\n    \/\/ Displaying the number \r\n    System.out.println(\"The number entered by user: \"+num);\r\n  }\r\n}<\/pre>\r\n<p>&nbsp;<\/p>\r\n<h3>Program Output<\/h3>\r\n<p><strong>Enter any number: 150<\/strong><br \/><strong>The number entered by user: 150<\/strong><\/p>\r\n<h3>Screenshot<\/h3>\r\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2134\" src=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/integer.png\" alt=\"\" width=\"830\" height=\"579\" title=\"\" srcset=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/integer.png 830w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/integer-300x209.png 300w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/integer-768x536.png 768w\" sizes=\"auto, (max-width: 830px) 100vw, 830px\" \/><\/p>\r\n<p>&nbsp;<\/p>\r\n","protected":false},"excerpt":{"rendered":"<p>Program Description Write a java program to read an integer entered by user. nextInt() method of the Scanner class will read the user input integer from the Standard input ( System.in) . We will declare a variable to hold the integer in our Java program. &nbsp; Java Program import java.util.Scanner; \/*********************************************************** * IntegerDemo.java * @program [&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-2079","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\/2079","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=2079"}],"version-history":[{"count":9,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/2079\/revisions"}],"predecessor-version":[{"id":23843,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/2079\/revisions\/23843"}],"wp:attachment":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/media?parent=2079"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/categories?post=2079"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/tags?post=2079"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}