Given 2 non negative numbers a and b, return true if both of them have the same last digit. For e.g. if the two numbers are 1268 and 80128 the output is true. If the two numbers are 901 and 9010 the output is false
Please comment if you find any mistake.
public class LastDigitPair {
static int testcase11 = 12;
static int testcase12 = 26;
static int testcase13 = 41;
public static void main(String args[]){
LastDigitPair testInstance = new LastDigitPair();
boolean result =
testInstance.isSameLastDigit(testcase11,testcase12,testcase13);
System.out.println(result);
}
//write your code
here
public boolean isSameLastDigit(int a, int b,int c){
boolean ans;
if(a<0 )
{
a=(-a);
}
else if(b<0)
{
b=(-b);
}
else if(c<0)
{
c=(-c);
}
int n1=a%10;
int n2=b%10;
int n3=c%10;
if((n1==n2)||(n1==n3)||(n2==n3))
{
ans=true;
}
else
{
ans=false;
}
return ans;
}
}
Please comment if you find any mistake.
No comments:
Post a Comment