Results 1 to 4 of 4
  1. #1
    camelCase is offline Member
    Join Date
    Jul 2014
    Posts
    1
    Rep Power
    0

    Default Array.asList display my input number

    import java.util.List;
    import java.util.Arrays;
    import java.util.Scanner;
    public class newProgram {

    public static void main(String[] args) {
    Scanner sc = new Scanner (System.in);
    System.out.println();
    int n = sc.nextInt();

    int array [] = new int [n];


    System.out.println("\nEnter array elements");

    int x = 0;
    int y = 1;
    while(x < n){

    System.out.println("Enter the "+y+" number");
    array [x] = sc.nextInt();
    x++;
    y++;

    }

    System.out.println("Arrays are:"+Arrays.toString(array)+"\n");
    System.out.println("Pick an array element");

    int find =sc.nextInt();

    int limit = Arrays.asList(array).indexOf(find);///////////ERROR HOW TO USE THIS PLEASE

    }

    }

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,017
    Rep Power
    10

    Default Re: Array.asList display my input number

    What error are you seeing?

    Can you please use the code tags to preserve formatting?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    6

    Default Re: Array.asList display my input number

    Try to use Integer array[] = new Integer[n];
    Otherwise you get a list with 1 element (the whole int array :D) and indexOf doesn`t find your primitive int.

  4. #4
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    843
    Rep Power
    6

    Default Re: Array.asList display my input number

    this type of assignment is anyway not useful for you.because Arrays.asList with primitive int array as a parameter will be
    List<int[]> intArrayList = Arrays.asList(array);//again arrayobject only u can retreive..so only one element in the list is Integer arrayobject...so ur find will not work.

    so better not to have this conversion..directly u search from array itself..
    Ramya:cool:

Similar Threads

  1. How can i display a number on a jlabel.
    By Shin in forum New To Java
    Replies: 4
    Last Post: 10-15-2012, 06:13 PM
  2. Display number of characters like bar chart
    By Dreaming in forum New To Java
    Replies: 6
    Last Post: 10-17-2011, 07:11 AM
  3. Replies: 14
    Last Post: 09-13-2011, 12:54 AM
  4. GUI text display input to list array
    By berndog in forum New To Java
    Replies: 1
    Last Post: 08-08-2010, 07:35 PM
  5. Finding a number in array close to another number
    By SteroidalPsycho in forum New To Java
    Replies: 2
    Last Post: 02-15-2010, 01:37 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
  •