Edit: oops meant to title "Scanner object cannot be resolved into a type"
I am trying to use the Scanner object in Java for a homework assignment.
Here's the program. It's written on notepad but compiled and run on a server belonging to the school.
Code:
import java.util.Scanner;
class Palindrome
{
public static boolean isPalindrome(String s)
{
if (s.length() <= 1)
{
return true; //base case
}
else if(s.charAt(s.length()) == s.charAt(0))
{
isPalindrome(s.substring(1, s.length() - 1)); //passes a new substring excluding first and last character
}
}
public static void main (String [] args)
{
System.out.println("Please input a string to see if it is a palindrome!");
Scanner keyboard = new Scanner(System.in);
String input = keyboard.nextLine();
if (isPalindrome(input) == true)
{
System.out.println(input + " is a palindrome!");
}
else
{
System.out.println(input + " is not a palindrome!");
}
}
}
I was using Scanner without any problems last semester but upon compiling the program on the schools server I got this error.
Here's what happens when I type the command "java -version"
Code:
java version "1.5.0"
gij (GNU libgcj) version 4.2.4 (Ubuntu 4.2.4-1ubuntu3
)
And here's "javac -version"
Code:
gcj-4.2 (GCC) 4.2.4 (Ubuntu 4.2.4-1ubuntu3)
The javac command only showing some ubuntu info troubles me, but I don't understand how that could be a problem on my end, seeing as how the programs are compiled and run on a different machine. I messed around with Eclipse a while ago, did I screw something up with the version of the compiler? I don't see how that would affect anything outside of Eclipse though...
Thanks for the help.
Bookmarks