No syntax errors, but run-time error exists?
//Class:
public class DigitExtractor {
//instance
private String digits;
private String array;
public DigitExtractor()
{
return;
}
public DigitExtractor(String digits)
{
this.digits=digits;
}
public String extract()
{
int diglength=digits.length();
for(int i = 0;i<(diglength-1);i++)
{
array=digits.substring(i);
}
return array;
}
}
//Tester
import java.util.Scanner;
public class DigitExtractorTester {
private static Scanner inputstring;
public static void main(String[] args)
{
System.out.println("type in #");
inputstring=new Scanner(System.in);
String digits=inputstring.toString();
DigitExtractor derp=new DigitExtractor(digits);
System.out.println(derp.extract());
}
}
//Output:
I expected the scanner to start, but it did not.
The console displayed:
type in # //from the System.out.println in the tester program
//and
E]
What does the "E]" mean?
Re: No syntax errors, but run-time error exists?
Code:
String digits=inputstring.toString();
You're getting the toString() representation of a Scanner object, which is not what you want and which is not how you use a Scanner object.
You may want to read the API entry for this or the tutorial. For my money, I'd use its nextLine() method. Also your extract() method doesn't make much sense to me.
It's a good lesson though: lack of syntax errors will only get you so far. The program still must make logical sense.