Requirement is to search a particular String in the Array of String value. To achieve this we need to have some set string values in a String array and secondly we need to have a String value to be searched.

Tips to Proceed...

1. Take counter
2. Iterate String and match the value on each iteration using equals() method.

Steps to do....

1. Take a counter count=0 .
2. Get the String to be searched.
3. Iterate the String Array and keep on searching from index=0 till length.
4. While looping keep on matching the string value with each index value of the Array.
5. If it get matched print "Match Found" and increment a counter.
6. If not matched then Print " No Match Found ".

Program :


public class Lab1{

    public static void main(String args[]){

 int count=0;
  
 String arr[]= new String[10];
 Scanner sc = new Scanner(System.in);
 System.out.println("Enter the String ");

 for(int i=0;i<10;i++){    // Iterate loop to store value in Array
     System.out.print((i+1)+". ");
     arr[i]=sc.next();
 }

 System.out.println("Enter the String to be searched");
 String s=sc.next();      // Enter value to be searched
  
 for(int i=0;i<arr.length;i++){ // Loop to search the Element
     if(s.equals(arr[i])){  
  System.out.println("Match Found");
  count++;
     }
 }
        
        if(count==0)     // Checking No Such Element Present in Array
          System.out.println("No Element Found ");

 System.out.println("No of Words Found in Number:"+count);
  
 }
}









Related Posts:

  • Relational Operator in Java Relational Operator in Java is used where we use any comparison between two value or two variable or a value and a variable, but while comparing variables , it must some numeral value and hence all the operators used for … Read More
  • Assignment Operator ( = ) in Java It is a kind of operator which has a wide use in any programming language and as it name suggest it is used to assign value to a variable and that value may be a direct value or a variable or we can say that it is used to a… Read More
  • Logical and bit-wise operators in java In java both logical and bitwise operators are used. Logical operator returns the true / false value depends on the condition check and bitwise return the same true / false depends on the condition check but the difference … Read More
  • " new " and " instanceof " Operator in Java new operator refers to the object creation where as instanceof used with the reference variable. Details of which we are going to discuss late in this topic.  What is " new " Operator and its uses in Java ? … Read More
  • Increments (++) and Decrements (--) Operators in Java This is most useful and confusing operator in java or any programming language. It is used to increase and decrease the value of a variable by 1. It is a Unary operator but the operand must be a variable containing num… Read More

37 comments:

  1. Thanks for sharing this here. I need details of Tally Solutions

    ReplyDelete
  2. Thanks for the information about this Really nice Post.to know more good and intresting topics.Know More

    ReplyDelete
  3. I ‘d mention that most of us visitors are endowed to exist in a fabulous place with very many wonderful individuals with very helpful things.

    bullet force hack android

    ReplyDelete
  4. Very nice blog. It is very useful for us. Thanks for good information.Visit here :bullet boy game

    ReplyDelete
  5. I Love your article. You can visit my website : armored core pc download

    ReplyDelete
  6. Nice Blog and very useful content to read and implement.
    Read similar and useful content...https://www.tallyerp9dubai.com/tally-erp-9-support.html

    ReplyDelete
  7. thanks for making java tutorial useful for java beginners in IT Sector



    Tally UAE

    ReplyDelete

Ads 468x60px

.

Ads

.

Featured Posts

Popular Posts

Like Us On FaceBook

Total Pageviews

201978

Online Members

Live Traffic