过滤二维数组并使用其数据创建新数组

时间:2018-02-05 17:12:26

标签: java arrays

请告诉我,如何实现以下任务? 我需要按字符串的最后一个值过滤数组,将其放入一个新数组中。 那些。在此示例中,1行应该在1个数组中,而在第二个中,另外2个应该在1个数组中。 我检查了数组是否存在像我这样的特定值

public class arr {
    public static void main(String[] args) throws IOException {
        String[][] matrixA = {
                {"1", "1", "a"},
                {"2", "2", "c"},
                {"3", "3", "c"}};

        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {


                boolean x  = Arrays.asList(matrixA).contains("a");
                if (x==true)
                {

                }


                boolean c  = Arrays.asList(matrixA).contains("c");
                if (c==true)
                {

                }

                System.out.print(matrixA[i][j] + " ");
            }
            System.out.println();
        }
    }
}

但我无法弄清楚如何进一步将整行写入新阵列?

    Arr1{
     {"1", "1", "a"}};
    Arr2{
     {"2", "2", "c"},
     {"3", "3", "c"}};

最后必须有2个数组

%include "along32.inc"

section .data

intA dq 0; Holds the input value
total dq 0; Holds the sum of the entered values
average dq 0; Holds the average of the values entered
counter dq 0; Keeps up with how many values are entered

pleasentry db "Hello!, I will find the average of the numbers you enter.", 0
instruction db "Enter a value. Once you have entered all your values, enter             a 0.", 0
inPut db "Please enter a value.", 0
theAverage db "The average is: ", 0



section .text
    global _start

_start:

;Pleasentry
    mov edx, pleasentry
    call WriteString
    call Crlf

;Instructions
    mov edx, instruction
    call WriteString
    call Crlf
    jmp again

;Meat of the program
again:
    mov edx, inPut
    call WriteString
    call ReadInt
    mov [intA], eax
    cmp eax, 0
    je final
    jne next

;Adds the input to the total and increments the counter by 1
next:
    mov ebx, total
    add eax, ebx
    mov [total], eax
    mov ecx, counter
    inc ecx
    mov [counter], ecx
    jmp again

;Does the math and exits the program
final:
    mov eax, total
    call WriteInt
    mov ebx, counter
    call WriteInt
    cdq
    idiv ebx
    mov [average], eax
    mov edx, theAverage
    call WriteString
    call WriteInt
    jmp exit

exit:
    mov eax, 01h
    mov ebx, 0h

    int 80h

0 个答案:

没有答案