50011
This question examines how to define method. Method mainly by
-Return value
-Method Name
-List of parameters (argument lists)
-Methods body (method body)
Composition
The Max method for this question is probably:
int max (int A, int b, int c) { //...}
60001 averaging
Note the frequently occurring error: integer except integer, the result is still an integer.
60002 finding the maximum value and its subscript
This topic examines how to iterate over an array:
for (int i = 0; i < array.length; + + i) { //via Arrray[i] to access the elements of the array i}
60003 Reverse Output
To access an array in reverse order:
for (int i = array.length-1; I >= 0;---I) { //Todo}
60004 switching minimum and maximum values
Thinking of solving problems
1. By 60002, we can find the maximum value and its subscript. This allows the value maximum to be exchanged with the array element array[0].
2. Slightly modify the program, we can find the minimum value and its following table. This allows you to swap the value minimal with the element at the end of the array array[array.length-1].
3. How to Exchange. You can refer to the following code for reuse (which can be called in 1, 2 steps)
Interchange array[idx1] and array[idx2]static void Swap (int[] array, int idx1, int idx2) { int temp = array[idx1]; ARRAY[IDX1] = array[idx2]; ARRAY[IDX2] = temp;} In the main function, if you have the following array int[] A = new int[] {0, 1, 2, 3};//the following swap function, array A will become {3, 1, 2, 0}swap (A, 0, a.length-1);
The code that roughly depicts the problem-solving idea is as follows:
public static void Main (string[] args) { //... for (int ri = 0; ri < repeat; + + ri) { int nums = new Int[n]; Input n numbers //... int maxidx = MINIDX = 0; for (int i = 0; i < n; + + i) { //Find the real maxidx and Minidx here } swap (nums, MAXIDX, 0); Swap (Nums, MINIDX, nums.length-1);} } static void Swap (int[] array, int idx1, int idx2) { int temp = array[idx1]; ARRAY[IDX1] = array[idx2]; ARRAY[IDX2] = temp;}
60011 matrix Operations
1. The following code provides access to the elements of line I, Column J, in the Matrix:
for (int i = 0; i < n; + + i) for (int j = 0; J < N; + + j) //Todo ... Note: If you want to execute more than one statement in for, you need to add curly braces
2. Read test instructions, onlywhile satisfyingThe following three cases of numbers can be added to the sum:
-Not on the last line (i! =?)
-Not in the last column (j! =?)
-Not on the diagonal (i + j! =?)
[Java] Experiment 10