IBM
Company
Programming
Arrays
JAVA PROGRAM IN SEARCH CHARACTER IN A STRING
Read Solution (Total 3)
-
- import java.util.*;
import java.io.*;
import java.lang.*;
class SearchChar
{
public static void main (String[] args)
{
int position=0;
System.out.println("Enter The String: ");
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();
System.out.println("Enter The Character to find: ");
char ch=sc.next().charAt(0);
position=str.indexOf(ch);
if(position>0)
System.out.println("The position of "+ch+" is "+(position+1));
else
System.out.println(ch+" is not Present in the Given string");
}
} - 7 years agoHelpfull: Yes(6) No(0)
- import java.io.*;
import java.util.*;
class SearchChar
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int count=0;
System.out.println("Enter the string: ");
String s=sc.nextLine();
char[] ch=s.toCharArray();
System.out.println("Enter any character: ");
char c=sc.next().charAt(0);
for(int i=0;i - 6 years agoHelpfull: Yes(0) No(0)
- import java.lang.*;
import java.util.Scanner;
class Search
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
String a;
char b;
System.out.println("Enter String:");
a=in.nextLine();
System.out.println("Enter the character you want to search:");
b=in.next().charAt(0);
int flag=0;
int x=a.length();
for(int i=0;i - 6 years agoHelpfull: Yes(0) No(0)
IBM Other Question