{"id":1413,"date":"2022-03-03T19:35:13","date_gmt":"2022-03-03T19:35:13","guid":{"rendered":"https:\/\/mdr.foobrdigital.com\/?p=1413"},"modified":"2022-03-03T19:35:13","modified_gmt":"2022-03-03T19:35:13","slug":"program-to-get-input-from-user","status":"publish","type":"post","link":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/2022\/03\/03\/program-to-get-input-from-user\/","title":{"rendered":"Program to get input from user"},"content":{"rendered":"\n<p>In this tutorial we are gonna see&nbsp;<strong>how to accept input from user<\/strong>. We are using Scanner class to get the input. In the below example we are getting input String, integer and a float number. For this we are using following methods:<br>1) public String nextLine(): For getting input String<br>2) public int nextInt(): For integer input<br>3) public float nextFloat(): For float input<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Example:<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.Scanner;\n\nclass GetInputData\n{\n  public static void main(String args&#91;])\n  {\n     int num;\n     float fnum;\n     String str;\n \n     Scanner in = new Scanner(System.in);\n \n     \/\/Get input String\n     System.out.println(\"Enter a string: \");\n     str = in.nextLine();\n     System.out.println(\"Input String is: \"+str);\n \n     \/\/Get input Integer\n     System.out.println(\"Enter an integer: \");\n     num = in.nextInt();\n     System.out.println(\"Input Integer is: \"+num);\n \n     \/\/Get input float number\n     System.out.println(\"Enter a float number: \");\n     fnum = in.nextFloat();\n     System.out.println(\"Input Float number is: \"+fnum); \n  }\n}<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Enter a string: \nChaitanya\nInput String is: Chaitanya\nEnter an integer: \n27\nInput Integer is: 27\nEnter a float number: \n12.56\nInput Float number is: 12.56<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial we are gonna see&nbsp;how to accept input from user. We are using Scanner class to get the input. In the below example we are getting input String, integer and a float number. For this we are using following methods:1) public String nextLine(): For getting input String2) public int nextInt(): For integer input3) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[554],"tags":[],"_links":{"self":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/1413"}],"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=1413"}],"version-history":[{"count":0,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/1413\/revisions"}],"wp:attachment":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/media?parent=1413"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/categories?post=1413"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/tags?post=1413"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}