Here is my code
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
System.out.print("Type a word: ");
String userWord = reader.nextLine();
System.out.print("Length of the first part: ");
int userLength = Integer.parseInt(reader.nextLine());
System.out.println("Result: " + userWord.substring(0, userLength));
}
Result:
Type a word: hellothere
Length of the first part: 3
Result: hel
Starting index starts counting from 0 right? So shouldn't the result print "hell"?
0 = h
1 = e
2 = l
3 = l