{"id":9074,"date":"2015-03-17T20:34:54","date_gmt":"2015-03-17T20:34:54","guid":{"rendered":"http:\/\/www.oracletutoring.ca\/blog\/?p=9074"},"modified":"2015-03-17T20:34:54","modified_gmt":"2015-03-17T20:34:54","slug":"java-programming-a-scanner-example","status":"publish","type":"post","link":"https:\/\/www.oracletutoring.ca\/blog\/java-programming-a-scanner-example\/","title":{"rendered":"Java programming:  a Scanner example"},"content":{"rendered":"<h1>Due to popular demand, the tutor shows basic use of a Java Scanner.<\/h1>\n<p>I write Java programs for my own needs; I&#8217;m not a professional programmer.  The following simple Java program illustrates a basic way a scanner can be tested.<\/p>\n<p>The Scanner class is a Java utility that can read separate values from a stream of data.  One use of a scanner is to read through a line of data in which a number is expected.  If the number is in there, the scanner likely will find it, provided it doesn&#8217;t include any non-numeric characters.  Also, it seems, the number can&#8217;t be &#8220;touching&#8221; any non-numeric characters; it must be separate from other text.<\/p>\n<p>Here&#8217;s the little program I wrote:<br \/>\n<span style=\"font-family:monospace;color:purple\"><br \/>\nimport java.util.*;<br \/>\nclass TryScanner{<br \/>\npublic static void main(String[] args){<br \/>\nfor (int i=0;i&lt;args.length;i++){<br \/>\nScanner scan0=new Scanner(args[i]);<br \/>\nif(scan0.hasNextDouble()){<br \/>\nSystem.out.println(&#8220;Readable number:  &#8220;+scan0.nextDouble());<br \/>\n}<br \/>\n<br \/>\nelse{<br \/>\nSystem.out.println(&#8220;Not a readable number: &#8220;+scan0.next());<br \/>\n}<br \/>\n}\/\/<span style=\"color:orange\">end of for loop<\/span><br \/>\nSystem.out.println(&#8220;\\n\\nSee you again:)&#8221;);<br \/>\n}\/\/<span style=\"color:orange\">end of main() method<\/span><br \/>\n}\/\/<span style=\"color:orange\">end of class<\/span><\/p>\n<p>I ran this program on Windows; my Linux compiler can be more strict, but I&#8217;m optimistic it will work there too.<\/p>\n<p>To the Java programmers who will come looking for a scanner example:  hope this helps.  For my casual readers who aren&#8217;t as familiar with Java, I will be explaining how to get up and running with it in future posts.<\/p>\n<p>Tomorrow, I&#8217;ll discuss the program above and some findings from the tests I ran with it:)<\/p>\n<p>Source:<\/p>\n<p>Kurniawan, Budi.  <em>Java 5:  A Beginner&#8217;s Tutorial<\/em>.  2006:  Brainy Software Corp.<\/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>Due to popular demand, the tutor shows basic use of a Java Scanner. I write Java programs for my own needs; I&#8217;m not a professional programmer. The following simple Java program illustrates a basic way a scanner can be tested. &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/www.oracletutoring.ca\/blog\/java-programming-a-scanner-example\/\"> <span class=\"screen-reader-text\">Java programming:  a Scanner example<\/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":[602,603,606],"class_list":["post-9074","post","type-post","status-publish","format-standard","hentry","category-computer-science","tag-java-programming","tag-java-scanner-class","tag-java-scanner-example"],"_links":{"self":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/9074","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=9074"}],"version-history":[{"count":24,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/9074\/revisions"}],"predecessor-version":[{"id":9098,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/9074\/revisions\/9098"}],"wp:attachment":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/media?parent=9074"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/categories?post=9074"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/tags?post=9074"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}