Searching char in String
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Searching char in String

  1. #1
    Join Date
    Aug 2017
    Posts
    1

    Searching char in String

    Hi everybody,

    is anybody capable pls solve this problem ? I am trying to figure it out (without the knowledge of object oriented programming) for a few hours but I am still failing :-/.

    Write in Java a program that reads a character string (String ) and a character ( char ) and informs the user whether or not the character occurs in the string.

    An example:
    Hello! I try to find a character in a string.
    Please, enter string:
    Java
    Please, enter character:
    v
    Character v was found.

  2. #2
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,756

    Re: Searching char in String

    Look at the API doc for the String class. It has methods that will be useful for you.
    http://docs.oracle.com/javase/8/docs/api/index.html

    If you have some questions about your code, post your code (wrapped in code tags)
    and ask you questions.
    Norm

  3. #3
    Join Date
    Aug 2017
    Posts
    24

    Re: Searching char in String

    public class Matching
    {
    public static void main(String args[])
    {
    String str = "pqrpqrpqr";

    System.out.println(str.indexOf('r'));
    System.out.println(str.indexOf("qrp"));
    System.out.println(str.indexOf('u'));

    System.out.println(str.lastIndexOf('p'));

    System.out.println(str.charAt(3));
    System.out.println(str.length());
    System.out.println(str.charAt(12));
    }
    }

  4. #4
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,756

    Re: Searching char in String

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    Norm

Tags for this Thread

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This a Codeguru.com survey!


On-Demand Webinars (sponsored)