[英]java - Can someone explain to me what is going on? there's a lot of things going on in which I haven't been taught yet
public class Main {
public static void main(String[] args) {
int[] x = {1, 2, 3};
increase(x);
Reverse rev = new Reverse();
rev.reverse(x);
System.out.println(x[0] + " " + x[1] + " " + x[2]);
}
//Increase every element in the array by 1
//For example: array : 0, 1, 2 will become 1, 2, 3
public static void increase(int[] a) {
//TODO: FILL ME
}
}
class Reverse {
//Reverse the array
//For example: array 0, 1, 2 will become 2, 1, 0
public void reverse(int[] a) {
//TODO: FILL ME
}
}
什么增加(x); 怎么辦? 基本上,我必須填寫他寫的內容。但是當我什至不了解正在發生的事情時,這很難。
現在, increase()
暫時不執行任何操作。
您的任務是以增加陣列中每個單元格內容的方式編寫方法的內容。
您的代碼做什么?
int[] x = {1, 2, 3}; // Create an array with 3 elements, "1", "2" and "3"
increase(x); // Call the increase() method which for now does nothing
Reverse rev = new Reverse(); // Create an instance of the Reverse class, which contains a method to reverse arrays (but does nothing for now)
rev.reverse(x); // Call the famous reverse() method.
System.out.println(x[0] + " " + x[1] + " " + x[2]); //Print the content of you array x[0] is the first cell, x[1] the second, etc.
語句increase(x)
調用靜態方法increase(int[] a)
。
由於該方法僅包含注釋,因此實際上不執行任何操作。 看來您的導師希望您將//TODO: FILL ME
注釋替換為可正確實現遞增方法的代碼。 您的導師在方法上方的注釋中描述了代碼應執行的操作;
//Increase every element in the array by 1
//For example: array : 0, 1, 2 will become 1, 2, 3
祝好運!
您要執行的操作是增加方法,使用for循環遍歷整數數組“ a”中的所有值。 然后,您應該為其分配一個比當前整數大1的整數。
我很想發布解決方案,但是那對您毫無幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.