import java.util.*;
public class CheckString
{
public static void main(String args[])
{
String s1;
char s2='a';
int count=0,j=0;
int arr[]=new int[25];
System.out.println("Enter your name");
Scanner in=new Scanner(System.in);
s1=in.nextLine();
int len=s1.length();
for(int i=0;i<len;i++)
{
if(s1.charAt(i)==s2)
{
count++;
arr[j]=i;
j++;
}
}
System.out.println("You name contains\t"+count+" times a \n");
System .out.println("a is present at following locations\n");
for(int k=0;k<j;k++)
{
System.out.println(arr[k]);
}
}
}
public class CheckString
{
public static void main(String args[])
{
String s1;
char s2='a';
int count=0,j=0;
int arr[]=new int[25];
System.out.println("Enter your name");
Scanner in=new Scanner(System.in);
s1=in.nextLine();
int len=s1.length();
for(int i=0;i<len;i++)
{
if(s1.charAt(i)==s2)
{
count++;
arr[j]=i;
j++;
}
}
System.out.println("You name contains\t"+count+" times a \n");
System .out.println("a is present at following locations\n");
for(int k=0;k<j;k++)
{
System.out.println(arr[k]);
}
}
}
No comments:
Post a Comment