{"id":9099,"date":"2015-03-18T17:58:13","date_gmt":"2015-03-18T17:58:13","guid":{"rendered":"http:\/\/www.oracletutoring.ca\/blog\/?p=9099"},"modified":"2015-03-18T17:58:13","modified_gmt":"2015-03-18T17:58:13","slug":"the-java-scanner-example-continued","status":"publish","type":"post","link":"https:\/\/www.oracletutoring.ca\/blog\/the-java-scanner-example-continued\/","title":{"rendered":"The Java Scanner example, continued"},"content":{"rendered":"<h1>The tutor continues discussing yesterday&#8217;s Java Scanner example.<\/h1>\n<p>&nbsp;<br \/>\nIn <a href=\"?p=9074\">yesterday&#8217;s post<\/a> I introduced a short program to test an instance of the Java Scanner.<\/p>\n<p>As of today, I&#8217;ve tried the program on both my Windows and my Linux systems.  It seems to work well on both.<\/p>\n<p>The point of the program is to test the Java Scanner&#8217;s ability to find numbers among other text.  For instance, does it know that $45.67 is a number?  How about 4.1e-2 (0.041 in scientific notation).  Or 6.75d?  (The &#8220;d&#8221; indicates type &#8220;double&#8221; in some Java contexts.)<\/p>\n<p>In the program, the wordings<br \/>\n<span style=\"font-family:monospace;color:purple\"><br \/>\nscan0.hasNextDouble()<br \/>\n<\/span><\/p>\n<p>and<br \/>\n<span style=\"font-family:monospace;color:purple\"><br \/>\nscan0.nextDouble()<br \/>\n<\/span><\/p>\n<p>mean that the scanner is looking for numbers of &#8220;double&#8221; type; i.e., decimals.  (Using other methods, the scanner could be set to look for integers, strings, or other types of values.)<\/p>\n<p>I first compiled the program thus:<br \/>\n<span style=\"font-family:monospace\"><br \/>\njavac TryScanner.java<br \/>\n<\/span><\/p>\n<p>Afterwards, I ran several tests.  Here&#8217;s one of my command line calls:<br \/>\n<span style=\"font-family:monospace\"><br \/>\njava -cp . TryScanner 78.1 here 45 $76.51 4.2e-3 655.2d<\/p>\n<p>The output:<br \/>\n<span style=\"font-family:monospace\"><br \/>\nReadable number:  78.1<br \/>\nNot a readable number:  here<br \/>\nReadable number:  45.0<br \/>\nNot a readable number:  $76.51<br \/>\nReadable number: 0.0042<br \/>\nNot a readable number:  655.2d<br \/>\nSee you again:)<br \/>\n<\/span><\/p>\n<p>So we see that the Java Scanner, in this example anyway, does not appreciate that $76.51 means a number.  It does, however, recognize 4.2e-3 as 0.0042, and 45 as 45.0.<\/p>\n<p>The call above was done on Windows; my Linux system mostly agrees, but not in every case (surprise, surprise&#8230;.:)  More on that next time.<\/p>\n<p>I realize that, with Java programming, I&#8217;ve opened an accordion file that could wrap around the world. <\/p>\n<p>Source:<\/p>\n<p><a href=\"http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/java\/util\/Scanner.html\">docs.oracle.com<\/a><\/p>\n<p>Jack of <a href=\"https:\/\/www.oracletutoring.ca\">Oracle Tutoring by Jack and Diane,<\/a> Campbell River, BC.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The tutor continues discussing yesterday&#8217;s Java Scanner example. &nbsp; In yesterday&#8217;s post I introduced a short program to test an instance of the Java Scanner. As of today, I&#8217;ve tried the program on both my Windows and my Linux systems. &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/www.oracletutoring.ca\/blog\/the-java-scanner-example-continued\/\"> <span class=\"screen-reader-text\">The Java Scanner example, continued<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[105],"tags":[605,610,609,602,607,611,608],"class_list":["post-9099","post","type-post","status-publish","format-standard","hentry","category-computer-science","tag-java-command-line-arguments","tag-java-on-linux","tag-java-on-windows","tag-java-programming","tag-java-scanner","tag-java-scanner-testing","tag-java-type-double"],"_links":{"self":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/9099","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/comments?post=9099"}],"version-history":[{"count":17,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/9099\/revisions"}],"predecessor-version":[{"id":9116,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/9099\/revisions\/9116"}],"wp:attachment":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/media?parent=9099"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/categories?post=9099"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/tags?post=9099"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}