Quantcast
Channel: Software Testing Forums
Viewing all articles
Browse latest Browse all 11978

Tester Challenges | Re: A mathematical Problem asked as a part of an interview

$
0
0
Hi,
I have a possible solution.

public class testersChallenge{
public static void main(String args[])throws Exception{
int a=999;
int b=999;
boolean stop =true;
int results=0;
String pal="";
while (stop) {
results=a*b;
pal=Integer.toString(results);
// I assume that there are a solution with a and b >=900
if (b<900) {
a=a-1;
b=999;
}
else {
// I will check if ABC is equal to CBA
if (pal.substring(0,3).equals(pal.substring(5,6) + pal.substring(4,5) + pal.substring(3,4))) stop=false;
else b=b-1;
}
}
System.out.println("The solution is : " + a + " * " + b + " = " + pal);
// The solution is : 993 * 913 = 906609
}
}

For a long time that I not programmed but I had fun a lot.
I'm sure that can be improved. Let's go!!
Regards!

Juan

Viewing all articles
Browse latest Browse all 11978

Trending Articles