Results 1 to 2 of 2
  1. #1
    Dave013 is offline Member
    Join Date
    Oct 2011
    Location
    Shrewsbury, Shropshire
    Posts
    6
    Rep Power
    0

    Default sorting and searching

    Is someone able to help me with this



    1 Rihanna
    2 Cheryl Cole
    3 Alexis Jordan
    4 Katy Perry
    5 Bruno Mars
    6 Cee Lo Green
    7 Mike Posner
    8 Nelly
    9 Duck Sauce
    10 The Saturdays

    Write a program that stores the names of these artists in a String array. The program should prompt the user to enter the name of an artist and output that artist's position in the charts or a message saying that they are not present.









    import java.util.*;

    class Sorting {

    private static int Rihanna;

    public static void main(String[] args) {
    String names[] = {"AAAA", "DDDD", "FFFF", "ZZZZ", "KKKKK", "PPPP"};
    ArrayList<String> list = new ArrayList<String>();
    for (int i = 0; i < names.length; i++) {
    list.add(names[Rihanna]);
    }
    Scanner input = new Scanner(System.in);
    System.out.print("Enter Name: ");
    String name = input.nextLine();


    int index;
    if (list.contains(name)) {


    if (list.contains(name)) {
    index = list.indexOf(Rihanna);
    System.out.println("Position: 1" + (index + 1));
    } else {
    System.out.println("Artist is not present");

    }
    }
    }
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,953
    Rep Power
    19

    Default Re: sorting and searching

    What is your problem?
    What does the above do (or not do) that is causing you trouble?

Similar Threads

  1. Searching
    By Harmesh Goyal in forum AWT / Swing
    Replies: 0
    Last Post: 03-02-2011, 02:36 PM
  2. Searching
    By peliukasss in forum Lucene
    Replies: 0
    Last Post: 04-07-2010, 01:05 AM
  3. Sorting/Searching Objects with multiple types.
    By gcampton in forum New To Java
    Replies: 20
    Last Post: 10-21-2009, 11:58 PM
  4. Replies: 2
    Last Post: 10-07-2009, 06:24 PM
  5. Replies: 0
    Last Post: 04-14-2008, 08:39 PM

Posting Permissions

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