{"id":1463,"date":"2022-08-01T19:43:09","date_gmt":"2022-08-01T19:43:09","guid":{"rendered":"https:\/\/gyanipandit.com\/programming\/?p=1463"},"modified":"2022-08-18T11:46:03","modified_gmt":"2022-08-18T11:46:03","slug":"scanner-next-method-java","status":"publish","type":"post","link":"https:\/\/gyanipandit.com\/programming\/scanner-next-method-java\/","title":{"rendered":"Scanner Next() Method Java"},"content":{"rendered":"\n<p class=\"has-text-align-center\"><strong>Next method<\/strong><\/p>\n\n\n\n<p>Now let&#8217;s discuss the next() method, with which we can take a complete token as an input from the user. This method returns the next complete token from the Scanner.<\/p>\n\n\n\n<h2 class=\"has-text-align-center wp-block-heading\">Get a complete token as input (next method)<\/h2>\n\n\n\n<p>Have a look at the below program which demonstrates the use of the next() method &#8211;<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background\">package com.company;<br>import java.util.Scanner;<br>public class Main {<br>public static void main(String[] args) {<br>Scanner scanner = new Scanner(System.in);<br>String word = scanner.next();<br>System.out.println(word);<br>}<br>}<\/p>\n\n\n\n<p>So, with the next() method, we can have only one word as user input. This means that if you give some user input like \u201cI am learning Java programming language\u201d, and if you try to print word (the variable in which we have stored the user input), you will get \u201cI\u201d as an output. This is because when it saw the space, it thought that the string has ended, and stored whatever is there before the space. If you want to get the whole line, like if you want to take such inputs from the user which are going to contain spaces, then you can better make use of the next line() method. This helps us take lines of text as user input.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Next method Now let&#8217;s discuss the next() method, with which we can take a complete token as an input from the user. This method returns the next complete token from the Scanner. Get a complete token as input (next method) Have a look at the below program which demonstrates the use of the next() method [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[12,11],"class_list":{"0":"post-1463","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-java-tutorial","7":"tag-java","8":"tag-java-tutorial"},"_links":{"self":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/1463","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/comments?post=1463"}],"version-history":[{"count":4,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/1463\/revisions"}],"predecessor-version":[{"id":2667,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/1463\/revisions\/2667"}],"wp:attachment":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/media?parent=1463"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/categories?post=1463"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/tags?post=1463"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}