【发布时间】:2018-01-20 19:02:04
【问题描述】:
我是编程新手,似乎无法解决这个问题。任何帮助表示赞赏,我目前显示了我的代码。非常感谢您。
输入的第一行包含要跟随的行数
- 每行的第一个数字
n >= 2包含该行后面的整数个数 - 这 n 个整数(每个整数
>= 0; <= 1000)一直到行尾,并且应该使用索引号1...n - 1存储在数组中(最后一个除外) - 行中的最后一个整数 p (
p >= 1 & p <= n - 1) 是要从行中选择并打印的整数的索引(从 1 开始)
到目前为止的代码:
public static void main(String[] args) {
// Scanner to take the inputs
Scanner input = new Scanner(System.in);
// Variables
int numOfLines;
int di = 0;
int n;
// The arrays to store the results
int[] data = new int[100];
int[] result = new int[100];
System.out.println("**Input**");
// Read number of lines to follow
numOfLines = input.nextInt();
while (di < numOfLines) {
// Read first integer of each line
n = input.nextInt();
// Store n-1 integers to array
for (int dj = 1; dj <= n - 1; dj++) {
data[dj] = input.nextInt();
}
// Multiply selected numbers and store to array
result[di] = data[dj];
di++;
}
}
【问题讨论】:
-
请take the tour 了解该网站的运作方式以及此处的主题有哪些问题,并edit 相应地提出您的问题。另见:Why is "Can someone help me?" not an actual question?