I am attempting to take a file of numbers of the format:
and place each digit in an array one at a time. I am getting a compile error (3, actually). Could someone help me understand what the errors are referring to? Let me know if you need to see more of my code (the program is a bit long and ugly at the moment).
When I change the expression to read
My errors change to:
File: C:\Users\Jo\Projects\ProjectEuler\PE013.java [line: 36]
Error: C:\Users\Jo\Projects\ProjectEuler\PE013.java:36: incompatible types
found : java.lang.String required: int
File: C:\Users\Jo\Projects\ProjectEuler\PE013.java [line: 69]
Error: C:\Users\Jo\Projects\ProjectEuler\PE013.java:69: int cannot be dereferenced
I'm not sure what's going on with line 69 either, but I don't think it would be related.
Or just use Scanner's nextInt method. As for converting anything to a String, there are a few overloaded static valueOf methods in the String class. You can use those to convert any value, including primitives and null, into Strings.
Joined: Aug 26, 2011
Thanks all! Good suggestions, and now I have it working and understand Java a bit better!