Google Coding Question
----------------------------------
1.TCS/Infosys
2.Amazon / Oracle
Input: "96{Amit985Ajit{ ]98";
Output: 96+985+98=1179
class GoogleTest
{
public static void main(String[] args)
{
String str="96{Amit985Ajit{ ]98";
char arr[]=str.toCharArray();
int sum=0;
int total=0;
for(int i=0;i<arr.length;i++){
if(arr[i]>='0' && arr[i]<='9'){
sum=sum*10+Character.getNumericValue(arr[i]);
}
else{
total=total+sum;
sum=0;
}
}
total=total+sum;
System.out.println(str);
System.out.println(total);
}
}
Comments
Post a Comment