Results 1 to 2 of 2
Thread: sorting and searching
- 12-09-2011, 10:15 AM #1
Member
- Join Date
- Oct 2011
- Location
- Shrewsbury, Shropshire
- Posts
- 6
- Rep Power
- 0
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");
}
}
}
}
- 12-09-2011, 12:19 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Similar Threads
-
Searching
By Harmesh Goyal in forum AWT / SwingReplies: 0Last Post: 03-02-2011, 02:36 PM -
Searching
By peliukasss in forum LuceneReplies: 0Last Post: 04-07-2010, 01:05 AM -
Sorting/Searching Objects with multiple types.
By gcampton in forum New To JavaReplies: 20Last Post: 10-21-2009, 11:58 PM -
Having trouble insert/sorting array values w/ binary searching.
By bh-chobo in forum New To JavaReplies: 2Last Post: 10-07-2009, 06:24 PM -
Sorting, Searching, and Inserting into a sorted array
By Java Tip in forum java.langReplies: 0Last Post: 04-14-2008, 08:39 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks