这是我的密码
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));
}
结果:
Type a word: hellothere
Length of the first part: 3
Result: hel
开始索引从0开始计数,对吗?那么结果不应该打印“地狱”吗?
1=e
2=l