Interviewer check your Programming Logic.
like Statement
String s="I am Bharat@123 from shirur";
find the integer in the string and addition them. for example 1,2,3 integer value and addition 1+2+3=6
find the latter in given String.for example "r" in the 2 string "Bharat" and "Shirur" then count is=2
String s="I am Bharat@123 from shirur";
am
like Statement
String s="I am Bharat@123 from shirur";
find the integer in the string and addition them. for example 1,2,3 integer value and addition 1+2+3=6
find the latter in given String.for example "r" in the 2 string "Bharat" and "Shirur" then count is=2
Program
String s="I am Bharat@123 from shirur";
char[] a=s.toCharArray();
int count=0,addition=0;
for(int i=0;i<a.length-1;i++)
{
if(Character.isDigit(a[i]))
{
int myInt = a[i] - '0';
addition=addition+ myInt;
System.out.println(addition+"number=="+a[i]);
}
}
String[] splits = s.split(" ");
for(int k=0;k<splits.length;k++)
{
System.out.println(splits[k]);
if(splits[k].indexOf("r") != -1)
{
count=count+1;
}
}
System.out.println("count=="+count);
System.out.println("addition=="+addition);
Out Put
I
No comments:
Post a Comment