public static void main(String [] args)
{
String str="asd123 dgw35df wi13gdf9";
StringBuffer strb;
int sum=0;
int len = str.length();
//char ch ;
for(int i=0;i<len;i++)
{
strb = new StringBuffer();
while(Character.isDigit(str.charAt(i)))
{
//System.out.println(i);
strb = strb.append(str.charAt(i));
i++;
if(i==len)
{
break;
}
}
String ggg =strb.toString();
int aaa = Integer.parseInt(ggg);
System.out.println("=="+aaa);
}
System.out.println("The total is "+ sum);
}
// OUTPUT is...
Exception in thread "main" java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at interview_Programs.Thermofisher_program.main(Thermofisher_program.java:33)
yes i tried with converting to string the converting to integer.
By using Integer.ParseInt();
But it is not workng..
I need to convert from Strinbuffer to Integer value to perform the operation…