I'm not quite sure what is wrong, and I am VERY new to programming but heres teh problem:

Scanner scanner;
scanner = new Scanner();

This is what I have, and this is the error message:

cannot find symbol
symbol: constructor Scanner()
location: class.java.util.Scanner

And also, there is a problem with another one of my codes that I'm not sure about...:

if(guess == secretWord)

error message:
Comparing String using =! or ==

not too sure about this one...anyways if anyone can help I would appreciate it.

for using the Scanner class, don't you need to make an import of the class?

import java.util.Scanner;

concerning your second question: the == and != are indeed not the right way to check whether two Strings are equal or not.

a String is an Object, and should be compared using the method equals() (or, equalsIgnoreCase())

for instance:

String guess = "guess";
String secret = "secret";

boolean test = guess.equals(secret);
// test = false;
  System.out.println("this line will be printed, since the two Strings are not equal");

The problem wasn't the import. It looked like the OP already had the import listed.

The problem is that the Scanner class does not provide a "default" constructor for Scanner objects.

For a list of proper Constructors for Scanner objects, refer to this link.

The most common use for a Scanner object is the provide a way for pulling specific information out of a File or InputStream.


import java.util.Scanner;

public class MyScannerTest{

	public static void main(String... args){

		Scanner kb = new Scanner(System.in);

		System.out.println("Enter something, please... anything!\n");
		System.out.println("\nYou entered: " + kb.next());

--though I think BufferedReader does the job much better than Scanner. Then again, each class solves a different problem in a similar way.

This article has been dead for over six months. Start a new discussion instead.