<p>I just installed Ubuntu 8.04 and I'm taking a course in Java so I figured why not install a IDE while I am installing it. So I pick my IDE of choice, Eclipse, and I make a very simple program, Hello World, to make sure everything is running smoothly. When I go to use Scanner for user input I get a very odd error:</p>

<p><b>My code:</b><pre>import java.util.Scanner;</p>

<p>class test {
    public static void main (String [] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("hi");
    }
}</pre></p>

<p><b>The output:</b></p>

<pre>
Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
    Scanner cannot be resolved to a type
    Scanner cannot be resolved to a type

   at test.main(test.java:5)
</pre>

[{'answer_id': 79551, 'author': 'Thomas', 'author_id': 14637, 'author_profile': 'https://Stackoverflow.com/users/14637', 'pm_score': 3, 'selected': True, 'text': "<p>The Scanner class is new in Java 5. I do not know what Hardy's default Java environment is, but it is not Sun's and therefore may be outdated.</p>\n\n<p>I recommend installing the package sun-java6-jdk to get the most up-to-date version, then telling Eclipse to use it.</p>\n"}, {'answer_id': 79557, 'author': 'tgdavies', 'author_id': 11002, 'author_profile': 'https://Stackoverflow.com/users/11002', 'pm_score': 0, 'selected': False, 'text': "<p>If you are using a version of Java before 1.5, java.util.Scanner doesn't exist.</p>\n\n<p>Which version of the JDK is your Eclipse project set up to use?</p>\n\n<p>Have a look at Project, Properties, Java Build Path -- look for the 'JRE System Library' entry, which should have a version number next to it.</p>\n"}, {'answer_id': 82475, 'author': 'Lee Theobald', 'author_id': 1900, 'author_profile': 'https://Stackoverflow.com/users/1900', 'pm_score': 0, 'selected': False, 'text': '<p>It could also be that although you are have JDK 1.5 or higher, the project has some specific settings set that tell it to compile as 1.4.  You can test this via Project >> Properties >> Java Compiler and ensure the "Compiler Compliance Level" is set to 1.5 or higher.</p>\n'}, {'answer_id': 473785, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>I know, It\'s quite a while since the question was posted. But the solution may still be of interest to anyone out there. It\'s actually quite simple...</p>\n\n<p>Under Ubuntu you need to set the java compiler "javac" to use sun\'s jdk instead of any other alternative. The difference to some of the answers posted so far is that I am talking about javac NOT java. To do so fire up a shell and do the following:</p>\n\n<ol>\n<li>As root or sudo type in at command line:</li>\n</ol>\n\n<p><code># update-alternatives --config javac</code></p>\n\n<ol start="2">\n<li><p>Locate the number pointing to sun\'s jdk, type in this number, and hit "ENTER".   </p></li>\n<li><p>You\'re done! From now on you can enjoy java.util.Scanner under Ubuntu.</p></li>\n</ol>\n\n<p><code>System.out.println("Say thank you, Mr.");\nScanner scanner = java.util.Scanner(System.in);\nString thanks = scanner.next();\nSystem.out.println("Your welcome.");</code></p>\n'}, {'answer_id': 60959558, 'author': 'boi yeet', 'author_id': 12864849, 'author_profile': 'https://Stackoverflow.com/users/12864849', 'pm_score': 0, 'selected': False, 'text': '<p>You imported Scanner but you\'re not using it. You\'re using Scanner, which requires user inputs. You\'re trying to print out one thing, but you\'re exposing the your program to the fact that you are going to use your own input, so it decides to print "Hello World" after you give a user input. But since you are not deciding what the program will print, the system gets confused since it doesn\'t know what to print. You need something like <code>int a=sc.nextInt();</code> or <code>String b=sc.nextLine();</code> and then give your user input. But you said you want <code>Hello World!</code>, so Scanner is redundant.</p>\n'}, {'answer_id': 68014889, 'author': 'ailar', 'author_id': 16177997, 'author_profile': 'https://Stackoverflow.com/users/16177997', 'pm_score': 0, 'selected': False, 'text': '<pre class="lang-java prettyprint-override"><code>package com.company;\n\nimport java.util.Scanner;\n\npublic class Main {\n\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        System.out.print(&quot;Input seconds: &quot;);\n        int num = in.nextInt();\n\n        for (int i = 1; i &lt;=num; i++) {\n\n            if(i%10==3)\n            {\n                System.out.println(i);\n            }\n        }\n\n    }\n}\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/79538', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/97220/']