{"id":258576,"date":"2024-04-28T21:04:42","date_gmt":"2024-04-28T21:04:42","guid":{"rendered":"https:\/\/namso-gen.co\/blog\/?p=258576"},"modified":"2024-04-28T21:04:42","modified_gmt":"2024-04-28T21:04:42","slug":"how-to-get-value-from-scanner-in-java","status":"publish","type":"post","link":"https:\/\/namso-gen.co\/blog\/how-to-get-value-from-scanner-in-java\/","title":{"rendered":"How to get value from Scanner in Java?"},"content":{"rendered":"<p>Java offers the <b>Scanner<\/b> class as a powerful tool for reading user input from the console. Whether you need to retrieve a single value or a complete line, the Scanner class provides a simple and efficient way to handle input operations. In this article, we will explore how to effectively use the Scanner class to get values in Java.<\/p>\n<p>The first step in utilizing the Scanner class is to create an instance of it. You can do so by including the following line of code at the beginning of your Java program:<\/p>\n<p>&#8220;`java<br \/>\nScanner scanner = new Scanner(System.in);<br \/>\n&#8220;`<\/p>\n<p>This line instantiates a new Scanner object named <b>scanner<\/b> that is capable of reading user input from the standard input stream.<\/p>\n<p>Now, let&#8217;s dive into the different methods provided by the Scanner class to obtain values:<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_62 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title \" >Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-value-from-scanner-in-java\/#1_Reading_Integer_Values\" title=\"1. Reading Integer Values\">1. Reading Integer Values<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-value-from-scanner-in-java\/#2_Reading_Floating-Point_Values\" title=\"2. Reading Floating-Point Values\">2. Reading Floating-Point Values<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-value-from-scanner-in-java\/#3_Reading_Strings\" title=\"3. Reading Strings\">3. Reading Strings<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-value-from-scanner-in-java\/#4_Reading_Characters\" title=\"4. Reading Characters\">4. Reading Characters<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-value-from-scanner-in-java\/#5_Handling_Input_Errors\" title=\"5. Handling Input Errors\">5. Handling Input Errors<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-value-from-scanner-in-java\/#6_Ignoring_Line_Breaks\" title=\"6. Ignoring Line Breaks\">6. Ignoring Line Breaks<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-value-from-scanner-in-java\/#7_Handling_the_End_of_Input\" title=\"7. Handling the End of Input\">7. Handling the End of Input<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-value-from-scanner-in-java\/#8_Specifying_the_Delimiter\" title=\"8. Specifying the Delimiter\">8. Specifying the Delimiter<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-value-from-scanner-in-java\/#9_Reading_Multiple_Values_on_a_Single_Line\" title=\"9. Reading Multiple Values on a Single Line\">9. Reading Multiple Values on a Single Line<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-value-from-scanner-in-java\/#10_Reading_Until_a_Specific_Value\" title=\"10. Reading Until a Specific Value\">10. Reading Until a Specific Value<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-value-from-scanner-in-java\/#11_Closing_the_Scanner\" title=\"11. Closing the Scanner\">11. Closing the Scanner<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-value-from-scanner-in-java\/#12_Why_is_it_important_to_handle_input_errors\" title=\"12. Why is it important to handle input errors?\">12. Why is it important to handle input errors?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-value-from-scanner-in-java\/#13_Can_the_Scanner_class_read_data_from_a_file\" title=\"13. Can the Scanner class read data from a file?\">13. Can the Scanner class read data from a file?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-value-from-scanner-in-java\/#14_Can_the_Scanner_class_be_used_for_reading_input_from_sources_other_than_the_console\" title=\"14. Can the Scanner class be used for reading input from sources other than the console?\">14. Can the Scanner class be used for reading input from sources other than the console?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-value-from-scanner-in-java\/#15_What_happens_if_the_input_type_provided_doesnt_match_the_expected_type\" title=\"15. What happens if the input type provided doesn&#8217;t match the expected type?\">15. What happens if the input type provided doesn&#8217;t match the expected type?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-value-from-scanner-in-java\/#16_Can_the_Scanner_class_handle_complex_input_patterns\" title=\"16. Can the Scanner class handle complex input patterns?\">16. Can the Scanner class handle complex input patterns?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-value-from-scanner-in-java\/#17_What_other_methods_does_the_Scanner_class_provide\" title=\"17. What other methods does the Scanner class provide?\">17. What other methods does the Scanner class provide?<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"1_Reading_Integer_Values\"><\/span>1. Reading Integer Values<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>To read an integer from the user, you can use the <b>nextInt()<\/b> method of the Scanner class:<\/p>\n<p>&#8220;`java<br \/>\nint number = scanner.nextInt();<br \/>\n&#8220;`<\/p>\n<h2><span class=\"ez-toc-section\" id=\"2_Reading_Floating-Point_Values\"><\/span>2. Reading Floating-Point Values<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>If you need to read a floating-point number, the <b>nextDouble()<\/b> method can be used:<\/p>\n<p>&#8220;`java<br \/>\ndouble decimal = scanner.nextDouble();<br \/>\n&#8220;`<\/p>\n<h2><span class=\"ez-toc-section\" id=\"3_Reading_Strings\"><\/span>3. Reading Strings<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>If the input consists of a single word or a line of text, you can use the <b>next()<\/b> or <b>nextLine()<\/b> methods, respectively:<\/p>\n<p>&#8220;`java<br \/>\nString name = scanner.next(); \/\/ Reads a single word<br \/>\nString sentence = scanner.nextLine(); \/\/ Reads a whole line<br \/>\n&#8220;`<\/p>\n<h2><span class=\"ez-toc-section\" id=\"4_Reading_Characters\"><\/span>4. Reading Characters<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>If you want to read a single character, the <b>next().charAt(0)<\/b> method can be helpful:<\/p>\n<p>&#8220;`java<br \/>\nchar ch = scanner.next().charAt(0);<br \/>\n&#8220;`<\/p>\n<h2><span class=\"ez-toc-section\" id=\"5_Handling_Input_Errors\"><\/span>5. Handling Input Errors<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The Scanner class provides various methods to deal with incorrect input. For example, if a user enters a non-numeric value when you&#8217;re expecting an integer, an <b>InputMismatchException<\/b> will occur. To handle such exceptions, you can use a try-catch block:<\/p>\n<p>&#8220;`java<br \/>\ntry {<br \/>\n    int number = scanner.nextInt();<br \/>\n} catch (InputMismatchException e) {<br \/>\n    System.out.println(&#8220;Invalid input! Please enter an integer.&#8221;);<br \/>\n}<br \/>\n&#8220;`<\/p>\n<h2><span class=\"ez-toc-section\" id=\"6_Ignoring_Line_Breaks\"><\/span>6. Ignoring Line Breaks<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>After reading a value from the Scanner, sometimes you may encounter issues due to line breaks remaining in the input buffer. To ignore these line breaks, you can use the <b>nextLine()<\/b> method after any <b>nextXXX()<\/b> method:<\/p>\n<p>&#8220;`java<br \/>\nint number = scanner.nextInt();<br \/>\nscanner.nextLine(); \/\/ Clears the input buffer<br \/>\nString text = scanner.nextLine(); \/\/ Reads the next line of text<br \/>\n&#8220;`<\/p>\n<h2><span class=\"ez-toc-section\" id=\"7_Handling_the_End_of_Input\"><\/span>7. Handling the End of Input<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>To check if the user has provided input, you can use the <b>hasNext()<\/b> method. It returns <b>true<\/b> if there is more input, and <b>false<\/b> otherwise:<\/p>\n<p>&#8220;`java<br \/>\nif (scanner.hasNext()) {<br \/>\n    \/\/ Process input here<br \/>\n} else {<br \/>\n    \/\/ Handle end of input<br \/>\n}<br \/>\n&#8220;`<\/p>\n<h2><span class=\"ez-toc-section\" id=\"8_Specifying_the_Delimiter\"><\/span>8. Specifying the Delimiter<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>By default, the Scanner class uses whitespace as the delimiter between tokens. However, you can change the delimiter by using the <b>useDelimiter()<\/b> method:<\/p>\n<p>&#8220;`java<br \/>\nscanner.useDelimiter(&#8220;,&#8221;); \/\/ Uses a comma as the delimiter<br \/>\n&#8220;`<\/p>\n<h2><span class=\"ez-toc-section\" id=\"9_Reading_Multiple_Values_on_a_Single_Line\"><\/span>9. Reading Multiple Values on a Single Line<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>If multiple values are provided on a single line, you can read them using the appropriate methods sequentially:<\/p>\n<p>&#8220;`java<br \/>\nint number1 = scanner.nextInt();<br \/>\nint number2 = scanner.nextInt();<br \/>\n&#8220;`<\/p>\n<h2><span class=\"ez-toc-section\" id=\"10_Reading_Until_a_Specific_Value\"><\/span>10. Reading Until a Specific Value<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>If you want to read values until a specific condition is met, you can utilize loops like <b>while<\/b> or <b>do-while<\/b> combined with appropriate conditional statements:<\/p>\n<p>&#8220;`java<br \/>\nwhile (scanner.hasNextInt()) {<br \/>\n    int number = scanner.nextInt();<br \/>\n    \/\/ Process the number<br \/>\n}<br \/>\n&#8220;`<\/p>\n<h2><span class=\"ez-toc-section\" id=\"11_Closing_the_Scanner\"><\/span>11. Closing the Scanner<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>It is crucial to close the Scanner once you have finished using it to free system resources. You can do this by calling the <b>close()<\/b> method:<\/p>\n<p>&#8220;`java<br \/>\nscanner.close();<br \/>\n&#8220;`<\/p>\n<h2><span class=\"ez-toc-section\" id=\"12_Why_is_it_important_to_handle_input_errors\"><\/span>12. <b>Why is it important to handle input errors?<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Handling input errors is essential to provide a robust and user-friendly experience. Without error handling, your program may crash abruptly if unexpected input is encountered.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"13_Can_the_Scanner_class_read_data_from_a_file\"><\/span>13. <b>Can the Scanner class read data from a file?<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Yes, the Scanner class can read data from a file by passing a File object as the parameter while creating the Scanner instance.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"14_Can_the_Scanner_class_be_used_for_reading_input_from_sources_other_than_the_console\"><\/span>14. <b>Can the Scanner class be used for reading input from sources other than the console?<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Yes, the Scanner class is versatile and can be used to read input from various sources, including files, strings, and network connections.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"15_What_happens_if_the_input_type_provided_doesnt_match_the_expected_type\"><\/span>15. <b>What happens if the input type provided doesn&#8217;t match the expected type?<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>If the input type provided doesn&#8217;t match the expected type, an InputMismatchException will be thrown. You can handle this exception to guide the user and prevent program crashes.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"16_Can_the_Scanner_class_handle_complex_input_patterns\"><\/span>16. <b>Can the Scanner class handle complex input patterns?<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Yes, the Scanner class can handle complex input patterns by utilizing regular expressions through the <b>findInLine()<\/b> method.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"17_What_other_methods_does_the_Scanner_class_provide\"><\/span>17. <b>What other methods does the Scanner class provide?<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Alongside the methods mentioned above, the Scanner class also provides various useful methods, such as <b>hasNextLine()<\/b> to check if the input has more lines, <b>nextBoolean()<\/b> to read boolean values, and <b>nextByte()<\/b> to read byte values, among others.<\/p>\n<p>By using the Scanner class effectively, you can easily obtain different types of values from the user, handle input errors gracefully, and make your Java programs more interactive and dynamic.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Java offers the Scanner class as a powerful tool for reading user input from the console. Whether you need to retrieve a single value or a complete line, the Scanner class provides a simple and efficient way to handle input operations. In this article, we will explore how to effectively use the Scanner class to &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"How to get value from Scanner in Java?\" class=\"read-more button\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-value-from-scanner-in-java\/#more-258576\">Read more<span class=\"screen-reader-text\">How to get value from Scanner in Java?<\/span><\/a><\/p>\n","protected":false},"author":65,"featured_media":107420,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[86279],"tags":[],"class_list":["post-258576","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-learn","no-featured-image-padding"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to get value from Scanner in Java?<\/title>\n<meta name=\"description\" content=\"Java offers the Scanner class as a powerful tool for reading user input from the console. Whether you need to retrieve a single value or a complete line,\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-value-from-scanner-in-java\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to get value from Scanner in Java?\" \/>\n<meta property=\"og:description\" content=\"Java offers the Scanner class as a powerful tool for reading user input from the console. Whether you need to retrieve a single value or a complete line,\" \/>\n<meta property=\"og:url\" content=\"https:\/\/namso-gen.co\/blog\/how-to-get-value-from-scanner-in-java\/\" \/>\n<meta property=\"og:site_name\" content=\"Namso Gen Blog - Free Credit Card Generator [100% Valid]\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/synchronyfinancial\" \/>\n<meta property=\"article:published_time\" content=\"2024-04-28T21:04:42+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/namso-gen.co\/blog\/wp-content\/uploads\/2024\/03\/faq.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Timothy Mathis\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@synchrony\" \/>\n<meta name=\"twitter:site\" content=\"@synchrony\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Timothy Mathis\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/namso-gen.co\/blog\/how-to-get-value-from-scanner-in-java\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/namso-gen.co\/blog\/how-to-get-value-from-scanner-in-java\/\"},\"author\":{\"name\":\"Timothy Mathis\",\"@id\":\"https:\/\/namso-gen.co\/blog\/#\/schema\/person\/ffa5be155490b2344e28f672fcc1e318\"},\"headline\":\"How to get value from Scanner in Java?\",\"datePublished\":\"2024-04-28T21:04:42+00:00\",\"dateModified\":\"2024-04-28T21:04:42+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/namso-gen.co\/blog\/how-to-get-value-from-scanner-in-java\/\"},\"wordCount\":800,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/namso-gen.co\/blog\/#organization\"},\"articleSection\":[\"Learn\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/namso-gen.co\/blog\/how-to-get-value-from-scanner-in-java\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/namso-gen.co\/blog\/how-to-get-value-from-scanner-in-java\/\",\"url\":\"https:\/\/namso-gen.co\/blog\/how-to-get-value-from-scanner-in-java\/\",\"name\":\"How to get value from Scanner in Java?\",\"isPartOf\":{\"@id\":\"https:\/\/namso-gen.co\/blog\/#website\"},\"datePublished\":\"2024-04-28T21:04:42+00:00\",\"dateModified\":\"2024-04-28T21:04:42+00:00\",\"description\":\"Java offers the Scanner class as a powerful tool for reading user input from the console. Whether you need to retrieve a single value or a complete line,\",\"breadcrumb\":{\"@id\":\"https:\/\/namso-gen.co\/blog\/how-to-get-value-from-scanner-in-java\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/namso-gen.co\/blog\/how-to-get-value-from-scanner-in-java\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/namso-gen.co\/blog\/how-to-get-value-from-scanner-in-java\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/namso-gen.co\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to get value from Scanner in Java?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/namso-gen.co\/blog\/#website\",\"url\":\"https:\/\/namso-gen.co\/blog\/\",\"name\":\"Namso Gen Blog - Free Credit Card Generator [100% Valid]\",\"description\":\"In Namso gen blog you can get many tips regarding to Credit cards, VCC, Credit card security etc. You can generate credit cards by using Namso-gen.co\",\"publisher\":{\"@id\":\"https:\/\/namso-gen.co\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/namso-gen.co\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/namso-gen.co\/blog\/#organization\",\"name\":\"Namso Gen Blog - Free Credit Card Generator [100% Valid]\",\"url\":\"https:\/\/namso-gen.co\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/namso-gen.co\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/namso-gen.co\/blog\/wp-content\/uploads\/2020\/07\/namso-gen-logo.png\",\"contentUrl\":\"https:\/\/namso-gen.co\/blog\/wp-content\/uploads\/2020\/07\/namso-gen-logo.png\",\"width\":500,\"height\":164,\"caption\":\"Namso Gen Blog - Free Credit Card Generator [100% Valid]\"},\"image\":{\"@id\":\"https:\/\/namso-gen.co\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/synchronyfinancial\",\"https:\/\/twitter.com\/synchrony\",\"https:\/\/www.youtube.com\/synchronyfinancial\",\"https:\/\/www.instagram.com\/synchrony\",\"https:\/\/www.linkedin.com\/company\/synchrony-financial\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/namso-gen.co\/blog\/#\/schema\/person\/ffa5be155490b2344e28f672fcc1e318\",\"name\":\"Timothy Mathis\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/namso-gen.co\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g\",\"caption\":\"Timothy Mathis\"},\"description\":\"Guest author Timothy Mathis has meticulously crafted and revised this article to the best of their knowledge and understanding. Readers are strongly advised to exercise caution, verify information independently, and rely on their own judgment when considering the information provided. Read more articles on Namso Gen here.\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to get value from Scanner in Java?","description":"Java offers the Scanner class as a powerful tool for reading user input from the console. Whether you need to retrieve a single value or a complete line,","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/namso-gen.co\/blog\/how-to-get-value-from-scanner-in-java\/","og_locale":"en_US","og_type":"article","og_title":"How to get value from Scanner in Java?","og_description":"Java offers the Scanner class as a powerful tool for reading user input from the console. Whether you need to retrieve a single value or a complete line,","og_url":"https:\/\/namso-gen.co\/blog\/how-to-get-value-from-scanner-in-java\/","og_site_name":"Namso Gen Blog - Free Credit Card Generator [100% Valid]","article_publisher":"https:\/\/www.facebook.com\/synchronyfinancial","article_published_time":"2024-04-28T21:04:42+00:00","og_image":[{"width":1200,"height":630,"url":"https:\/\/namso-gen.co\/blog\/wp-content\/uploads\/2024\/03\/faq.png","type":"image\/png"}],"author":"Timothy Mathis","twitter_card":"summary_large_image","twitter_creator":"@synchrony","twitter_site":"@synchrony","twitter_misc":{"Written by":"Timothy Mathis","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/namso-gen.co\/blog\/how-to-get-value-from-scanner-in-java\/#article","isPartOf":{"@id":"https:\/\/namso-gen.co\/blog\/how-to-get-value-from-scanner-in-java\/"},"author":{"name":"Timothy Mathis","@id":"https:\/\/namso-gen.co\/blog\/#\/schema\/person\/ffa5be155490b2344e28f672fcc1e318"},"headline":"How to get value from Scanner in Java?","datePublished":"2024-04-28T21:04:42+00:00","dateModified":"2024-04-28T21:04:42+00:00","mainEntityOfPage":{"@id":"https:\/\/namso-gen.co\/blog\/how-to-get-value-from-scanner-in-java\/"},"wordCount":800,"commentCount":0,"publisher":{"@id":"https:\/\/namso-gen.co\/blog\/#organization"},"articleSection":["Learn"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/namso-gen.co\/blog\/how-to-get-value-from-scanner-in-java\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/namso-gen.co\/blog\/how-to-get-value-from-scanner-in-java\/","url":"https:\/\/namso-gen.co\/blog\/how-to-get-value-from-scanner-in-java\/","name":"How to get value from Scanner in Java?","isPartOf":{"@id":"https:\/\/namso-gen.co\/blog\/#website"},"datePublished":"2024-04-28T21:04:42+00:00","dateModified":"2024-04-28T21:04:42+00:00","description":"Java offers the Scanner class as a powerful tool for reading user input from the console. Whether you need to retrieve a single value or a complete line,","breadcrumb":{"@id":"https:\/\/namso-gen.co\/blog\/how-to-get-value-from-scanner-in-java\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/namso-gen.co\/blog\/how-to-get-value-from-scanner-in-java\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/namso-gen.co\/blog\/how-to-get-value-from-scanner-in-java\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/namso-gen.co\/blog\/"},{"@type":"ListItem","position":2,"name":"How to get value from Scanner in Java?"}]},{"@type":"WebSite","@id":"https:\/\/namso-gen.co\/blog\/#website","url":"https:\/\/namso-gen.co\/blog\/","name":"Namso Gen Blog - Free Credit Card Generator [100% Valid]","description":"In Namso gen blog you can get many tips regarding to Credit cards, VCC, Credit card security etc. You can generate credit cards by using Namso-gen.co","publisher":{"@id":"https:\/\/namso-gen.co\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/namso-gen.co\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/namso-gen.co\/blog\/#organization","name":"Namso Gen Blog - Free Credit Card Generator [100% Valid]","url":"https:\/\/namso-gen.co\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/namso-gen.co\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/namso-gen.co\/blog\/wp-content\/uploads\/2020\/07\/namso-gen-logo.png","contentUrl":"https:\/\/namso-gen.co\/blog\/wp-content\/uploads\/2020\/07\/namso-gen-logo.png","width":500,"height":164,"caption":"Namso Gen Blog - Free Credit Card Generator [100% Valid]"},"image":{"@id":"https:\/\/namso-gen.co\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/synchronyfinancial","https:\/\/twitter.com\/synchrony","https:\/\/www.youtube.com\/synchronyfinancial","https:\/\/www.instagram.com\/synchrony","https:\/\/www.linkedin.com\/company\/synchrony-financial"]},{"@type":"Person","@id":"https:\/\/namso-gen.co\/blog\/#\/schema\/person\/ffa5be155490b2344e28f672fcc1e318","name":"Timothy Mathis","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/namso-gen.co\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g","caption":"Timothy Mathis"},"description":"Guest author Timothy Mathis has meticulously crafted and revised this article to the best of their knowledge and understanding. Readers are strongly advised to exercise caution, verify information independently, and rely on their own judgment when considering the information provided. Read more articles on Namso Gen here."}]}},"_links":{"self":[{"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/posts\/258576","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/users\/65"}],"replies":[{"embeddable":true,"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/comments?post=258576"}],"version-history":[{"count":0,"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/posts\/258576\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/media\/107420"}],"wp:attachment":[{"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/media?parent=258576"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/categories?post=258576"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/tags?post=258576"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}