开发者

method that stores inputs into an array [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 10 years ago.

I am trying to write a method that prompts the user to input 20 numbers开发者_开发百科 and stores the numbers in an alpha array. For some reason it is not working. Below is a sample of my method:

public  void inputArray(int a,int[]b){
    b=new int[20];
    int n=0;//int a;
    while(n<5){
        for(int i=0;i<alpha.length;i++){
            //a=window.readInt("please enter no  :");
            alpha[n]=a;
            n++;
        }
    }
}


I am writing a sample java code

import java.util.*;
void input(int []a)
{
     Scanner sc =new Scanner(System.in);  
     for(int i=0;i<20;i++)?
     {
     System.out.println("Enter a number ="):
     a[i]=  sc.nextInt();
     }
}

This java code is not complete .You can Google for How To input data from User for your specific programming language.


You must use Scanner or BufferReader as you wish, I thinks thats the simple way of doing I hope I can help

import java.util.Scanner;

public class Prueba {

static int alpha[] = new int[20];
static Scanner scan = new Scanner(System.in);

public static void main(String args[]) {

    int array[] = new int[20];
    array = inputArray(alpha);

}

public static int[] inputArray(int alpha[]) {
    for (int i = 0; i < alpha.length; i++) {
        alpha[i] = scan.nextInt();
        System.out.println(alpha[i]);
    }
    return alpha;

}

}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜