-
August 16th, 2017, 09:21 AM
#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.
-
August 16th, 2017, 10:20 AM
#2
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
-
August 18th, 2017, 11:08 PM
#3
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));
}
}
-
August 19th, 2017, 05:41 AM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|