Bank of America Interview Question
Software Engineer / Developers<pre lang="c" line="1" title="CodeMonkey33935" class="run-this">#include <stdio.h>
#include <string.h>
int main()
{
char *s = "12345";
char *p;
int sum = 0;
for(p = s; *p!='\0';p++)
sum = sum*10 + ((int)*p-'0');
printf("%d\n", sum);
return 0;
}
</pre><pre title="CodeMonkey33935" input="yes">
</pre>
Here is the solution...
public static void main(String args[]){
String numStr = "123456";
// 1*100000 (10^5)= 100000
// 2*10000 (10^4) = 20000
// 3*1000 (10^3) = 3000
// 4*100 (10^2) = 400
// 5*10 (10^1) = 50
// 6*1 (10^0) = 6
// ------------------------
// 123456
// ------------------------
int length = numStr.length();
char[] charArr = numStr.toCharArray();
int total = 0;
int index=length-1;
for(int i=0;i<length;i++){
total = (int) (total + (charArr[index]-48)*Math.pow(10, i));
index--;
}
System.out.println(total);
}
public class ConvertStringToNumber{
public static int convertToNum(String numStr){
Char ch[ ] = numStr.toCharArray();
int sum = 0;
into zeroAsValue = (int) '0';
for(char c : ch){
into tempZeroAsValue = (int) c;
sum = (sum*10) + (tempZeroAsValue - zeroAsValue);
}
system.out.println("convertedValueIs===>" +sum);
retun sum;
}
public static void main(String arg[ ] ){
String convertString = "98989"
convertToNum(convertString);
}
}
I had a few interviews with financial companies and they mostly ask stupid questions like this. Few of them actually ask questions on syntactical errors and code based errors and evaluate a candidate's skills. It's stupid to evaluate someone's skills on that basis. I guess thats the reason we have so many stupid financial institutions n even though they rob people of their money their software sux bawls.
"Elegance is not a dispensable luxury but a factor that decides between success and failure." -Edsger Dijkstra
These companies don't spend on clever programmers, they spend on marketing. An elegant product will succeed no matter what, even if it is not marketed
- gamodg November 01, 2010