- package com.aduvm.practice;
- public class FInd {
- /**
- * @param args
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- int[] a = {8,6,4,2,4,7,8,1,8,5,8,8};
- int[] arrArguments = new int[getIndex(a,8).length]; //建立与返回数组长度一样的数组
- arrArguments = getIndex(a,8);
- for(int arrArgument:arrArguments) //输出记录
- System.out.println( arrArgument);
-
- }
- public static int[] getIndex(int[] arr,int a)
- {
- int i = 0;
- int[] arrIndex = new int[arr.length]; //用于记录索引
- for(int x=0;x<arr.length;x++)
- {
- if(arr[x]==a){
- arrIndex[i] = x; //记录相同的值
- i++;
- }
- }
- return arrIndex; //程序不完整,仅供参考 ,返回值为0怎么处理?
- }
-
- }
复制代码 |