我需要帮助创建一个数组,计数达到给定的数字。输出应该是这个样子:创建一个数组,计数达到给定数
Enter a positive integer: 8
Counting up: 1 2 3 4 5 6 7 8
Counting down: 8 7 6 5 4 3 2 1
The first 8 multiples of 5: 5 10 15 20 25 30 35 40
The first 8 multiples of 10: 10 20 30 40 50 60 70 80
这是我到目前为止有:
Scanner input = new Scanner(System.in);
int[] myList = new int[1];
System.out.print("Enter a positive integer: ");
promptUser(myList);
int[] testArray = { 1, 1, 2, 3, 5, 8, 13 };
System.out.print("Test array: ");
printArray(testArray);
System.out.print("Counting up: ");
int[] countingUp = countUp(n);
printArray(countingUp);
}
public static void promptUser(int[] a){
Scanner input = new Scanner(System.in);
for(int i=0; i<a.length; i++){
a[i] = input.nextInt();
}
}
public static void printArray(int[] array){
for(int i=0; i<array.length; i++)
System.out.print(array[i]);
}
public static int[] countUp(int n){
for(int i=0; i<n; i++){
int count = 0;
while(count<n){
count++;
}
}
}
}
一切似乎除了叫countingUp最后的方法好吗工作。
非常感谢!
什么阵列做一个类'COUNTUP '回来?我根本没有看到任何'return'语句,这意味着你的程序不应该编译。 – ajb
编译器肯定会给你一些错误代码? – John3136
为什么你需要一个数组myList来存储单个数值? –