当用户输入单词时,系统会提示他们输入子字符串的第一个和第二个索引。我已经排序了这么多,但是当我尝试验证使用下面的 if 语句输入的索引时,我收到了有关这些 if 语句的错误,
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String inputString;
int startIndex;
int endIndex;
System.out.println("Enter a string : ");
inputString = scanner.nextLine();
System.out.println("Enter the first index of the substring : ");
startIndex = scanner.nextInt();
if (int startIndex > inputSting.length) {
System.out.println("Index is not in string length, try again.");
}
System.out.println("Enter the second index of the substring : ");
endIndex = scanner.nextInt();
if (int endIndex > inputSting.length) {
System.out.println("Index is not in string length, try again.");
}
char[] ch = new char[endIndex - startIndex + 1];
inputString.getChars(startIndex, endIndex + 1, ch, 0);
System.out.println("Output : " + String.valueOf(ch));
}
}
天涯尽头无女友
开满天机
相关分类