-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearchChar.java
More file actions
33 lines (29 loc) · 789 Bytes
/
SearchChar.java
File metadata and controls
33 lines (29 loc) · 789 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.util.Scanner;
public class SearchChar {
public static void main(String args[])
{
char ch;
int flag=0,pos=0;
String str = new String();
System.out.print("Enter the string: ");
Scanner sc = new Scanner(System.in);
str = sc.nextLine();
System.out.print("Enter the character to be searched: ");
ch = sc.next().charAt(0);
for(int i=0;i<str.length();i++)
{
if(str.charAt(i)==ch)
{
flag=1;
pos =i+1;
}
}
if(flag==1)
{
System.out.println("Character found at position "+pos);
}
else{
System.out.println("Character not found !!");
}
}
}