Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Java Sorting and Searching
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


David Ferguson
Java Sorting and Searching
1 Answer(s)      2 years and 10 months ago
Posted in : Java Beginners


If anyone could help me with this I would be really thankful!

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.

You should choose the most appropriate search method introduced in the lecture and modify it so that it handles strings, rather than integers.


Advertisement
View Answers

December 9, 2011 at 12:21 PM


import java.util.*;
class SearchingAndSorting 
{
    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[i]);
        }
        Scanner input=new Scanner(System.in);
        System.out.print("Enter Name: ");
        String name=input.nextLine();

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


    }
}


Related Tutorials/Questions & Answers:
Java Sorting and Searching
Java Sorting and Searching   If anyone could help me with this I would be really thankful! Write a program that stores the names of these artists in a String array. The program should prompt the user to enter the name
Sorting and Searching
Sorting and Searching  Hi i would really be thankful if someone could help me with this A program is required to ask users to rate the Java...) { Scanner input = new Scanner(System.in); System.out.print("Rate Java(0-10
Advertisements
Insertion, sorting and searching in array
to perform searching and sorting in array. In the java code given below we have...; } Insertion, sorting and searching in array   ... after sorting", array); // Search for element in specified array
Sorting in Java
Sorting in Java  Sorting in Java
Java sorting
Java sorting  can somebody help me know how java sorts? means which... the following links: Java bubble sort Java Heap Sort Java Insertion Sort Java Merge Sort Java Selection Sort Java Quick Sort   hello
Java String searching.
Java String searching.  How to search a string in given String array?   import java.util.Scanner; public class StringSearch { public... and for searching we used userCity.equalsIgnoreCase(city[i
Bubble Sorting in Java
Bubble Sorting in Java  Hi, What is Bubble Sorting? Guide me where to learn Bubble Sorting in Java? Thanks   Hi, Check the tutorial at Bubble Sorting in Java. Thanks
Java Sorting
Java Sorting  Could somebody help me with this question. Implement a program to process votes for 5 candidates in a talent contest. The program should use a String array to hold the names of the 5 candidates and an integer
Searching operation in JAva
Searching operation in JAva  Sir, I have made a project for the Dispatch section of my office. I have to search for letters that are dispatched on a particular date. Now there are thousands of letters dispatched on a particular
Searching operation in JAva
Searching operation in JAva  Sir, I have made a project for the Dispatch section of my office. I have to search for letters that are dispatched on a particular date. Now there are thousands of letters dispatched on a particular
Searching operation in JAva
Searching operation in JAva  Sir, I have made a project for the Dispatch section of my office. I have to search for letters that are dispatched on a particular date. Now there are thousands of letters dispatched on a particular
Searching operation in JAva
Searching operation in JAva  Sir, I have made a project for the Dispatch section of my office. I have to search for letters that are dispatched on a particular date. Now there are thousands of letters dispatched on a particular
Sorting
Sorting  can any help me know which sorting algorithm java uses for sorting collection and arrays
sorting array in java
sorting array in java  How to sort array in Java or JavaScript?   JavaScript Sorting array tutorial   Java Sort array of strings import java.util.*; class ArrayExample{ public static void main(String
Searching with alphabetical order - Java Beginners
Searching with alphabetical order  Hi, I want to this please help me Steps:- 1:-I have a one form of name text box with two button. 2:-user input in name text box(alphabetical order)search all fields from
Searching with alphabetical order - Java Beginners
Searching with alphabetical order  Hi, please understood my problem and send write code its very urgent I a write once again. Steps.... 2:-User input in the name text box(searching alphabetical order) name
Sorting in java - Java Beginners
Sorting in java  Hello.. I want you to help me with this question.. 1. A statistics company wants to keep information of families. The information of a family is the family name, the number of members and first name of each
java sorting codes - Java Beginners
java sorting codes  I want javasorting codes. please be kind enogh... the following link: http://www.roseindia.net/java/beginners/arrayexamples/ Here you will get various sorting algorithms. Hope that it will be helpful for you
java array sorting manual way
java array sorting manual way  Hi, Anyone has any sample code on how to sort a array manually without using the inbuild sorting algorithm? Thanks
merge sorting in arrays - Java Beginners
merge sorting in arrays  Write a program to insert string or characters to an array and apply merge sorting on this array  Hi Friend, Please visit the following link: http://www.roseindia.net/java/beginners
sorting
sorting   write a program to arrange sorting in rows,column and diagonal
Sorting algorithms - Java Beginners
Sorting algorithms  I'v being given an assignment and I still couldn't find a proper answer for the following questions.Can anyone pls pls help me wi it? 1)Compare and contrast efficiencies of Shell,Quick,Heap and Radix sort
SORTING - Java Interview Questions
("Items after sorting are ="+list); } } Thanks
Java Hashmap Sorting - Java Beginners
Java Hashmap Sorting   I have a sorting issue with a Hashmap. My constraint is that I MUST use the Hashmap and work with existing code. I do..., it loses the original alphabetical sorting done by the database. So, my problem
sorting - Java Beginners
; Easy Sorting: For all the values in the array A, find the largest and store
Java: Searching a string from doc files
Java: Searching a string from doc files   I want to search a string from DOC, DOCX files in java. Can anyone please help me
Array sorting - Java Beginners
Array sorting   Hello All. I need to sort one array based on the arrangement of another array. I fetch two arrays from somewhere and they are related. For example, String type[] = {"X","T","3","R","9"}; String
searching a text string in file - Java Beginners
searching a text string in file  code to match a string in a file that is already mentioned in java code.if the string matches any part of a string that whole string is printed
sorting
sorting  write to a program to arrange the sorting in rows, column and digonal
Searching a tex on a table in java! - Java Beginners
Searching a tex on a table in java!  i have a table which contains several data. using a textfield the item hat i search must be selected... the problem. For more information on Java visit to : http://www.roseindia.net
Comparison between the types of sorting in java
Comparison between the types of sorting in java  welcome all i wanna program in java compare between selection,insertion,bubble,merge,quick sort... of sorting. please help me thanks all
Advertisements
 

 

 

DMCA.com