May be the following will shed some light:
import java.util.Scanner;
public class Foo {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String delim = new String();
scanner.useDelimiter(delim);
// (A)
String a = new String();
String b = new String();
String c = new String();
String d = new String();
// (B)
System.out.print("Please enter a year: ");
a = scanner.next();
b = scanner.next();
c = scanner.next();
d = scanner.next();
// (C)
System.out.println("-->" + d + "<--");
System.out.println("\n".equals(d));
System.out.println((int)d.charAt(0));
System.out.println((int)"\n".charAt(0));
// (D)
String e = scanner.next();
System.out.println("\n".equals(e));
// (E)
String real = System.getProperty("line.separator");
System.out.println("d+e is the real line separator: " + (d+e).equals(real));
String bogus = System.getProperty("line.seperator");
System.out.println("d+e is the bogus line separator: " + (d+e).equals(bogus));
}
}
(I'm assuming a Windows OS)
I was going to comment on all of that, but am too lazy! Ask if anything is unclear. Notice I didn't bother to initialise
e with "new String()" as it seems a bit redundant to give a variable a value and then assign it another.
I think I would read the whole line and use the string method
toCharArray() for a task like this.