輸入3個整數n、begin、end。 首先,使用如下程式碼:
for(int i=0;i<n;i++)
將從0到n-1的數位拼接為字串str。如,n=12
,則拼接出來的字串為01234567891011
最後擷取字串str從begin到end(包括begin,但不包括end)之間的字串,並輸出。
10
5
8
1000
800
900
567
0330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNextInt()) {
int n, begin, end;
n = scanner.nextInt();
begin = scanner.nextInt();
end = scanner.nextInt();
StringBuilder str = new StringBuilder("");
for (int i = 0; i < n; i++) {
str.append(i);
}
System.out.println(str.substring(begin,end));
}
}
}