Results 1 to 2 of 2
  1. #1
    tipsydmano is offline Member
    Join Date
    Apr 2013
    Rep Power

    Default Java array problem

    *newbie java student

    So this is my problem:
    Task: Create a java program with a one-dimensional array (name it as arraySearch), the size of the array will given by the user upon run-time. Your program should also let the user to store elements in the array. Once the array has been populated with elements/values, your program should ask the user to give a number to be searched in the array. Ex: Search the element: 5. If there is an element 5 in your array, display it with its address, if there's none, display "Search Value is Not Found."

    So far i only have done this:

    public class arraySearch
    public static void main(String args[])throws IOException
    int[] myArray;
    int n,b,c,d,e,copy;

    BufferedReader buffer = new BufferedReader(new InputStreamReader(;

    System.out.print("Please specify the size of array: ");
    n = Integer.parseInt(buffer.readLine());
    copy = n;
    myArray = new int[n];
    System.out.print("Please specify the first element");
    b= Integer.parseInt(buffer.readLine());
    System.out.print("Please specify the second element");
    c= Integer.parseInt(buffer.readLine());
    System.out.print("Please specify the third element");
    d= Integer.parseInt(buffer.readLine());
    System.out.print("Please specify the fourth element");
    e= Integer.parseInt(buffer.readLine());
    int[] myArray= (b,c,d,e);

    it is still not finished because i dont know what will i do next :(
    and i dont know if my wriiten code is correct. Can you help me guys? Newbie java student

  2. #2
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Rep Power

    Default Re: Java array problem

    Hi tipsydmano, welcome.

    You would be better off using a for loop to accept user input. As it stands you have declared an array of size 'n', asked the user to input four entries and then recreate the array using the four values input by the user.
    Have you tried compiling and running the code because I would expect an error on the last line which should read as follows.

    Java Code:
    int[] myArray = [b]{[/b]b,c,d,e[b]}[/b]

Similar Threads

  1. JAVA problem array sorting
    By panter001nx in forum New To Java
    Replies: 10
    Last Post: 09-30-2012, 08:04 AM
  2. Java array matrix problem.. please help!
    By Asvin in forum New To Java
    Replies: 5
    Last Post: 04-11-2011, 07:35 PM
  3. Java Webservice problem (Array)
    By Gadge in forum New To Java
    Replies: 0
    Last Post: 01-10-2010, 04:55 PM
  4. Java Array object problem
    By kozik in forum New To Java
    Replies: 13
    Last Post: 04-20-2009, 10:37 PM
  5. Java array problem
    By cassysumandak in forum New To Java
    Replies: 4
    Last Post: 03-23-2009, 03:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts