Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: John Cooper   on Nov 28 In Java Category.

  
Question Answered By: Dustin Dean   on Nov 28

Try my sample program:

import java.io.*;


class InputArray
{
public static void main (String[] args) throws Exception
{
String[] sample = new String[5];
input(sample);
display(sample);
}


public static void input  (String[] args) throws Exception
{
BufferedReader in = new BufferedReader (new InputStreamReader
(System.in));

System.out.println ("Enter 5 values of the String array: ");

int i;

for (i = 0; i < args.length; i++)
{
args[i] = in.readLine();
}
}

public static void display (String[] args)
{
System.out.println ("\nDisplaying the values: ");

int i;

for (i = 0; i < args.length; i++)
{
System.out.println (args[i]);
}
}
}

Share: