Skip to content

Instantly share code, notes, and snippets.

@rhlmalik17
Created January 19, 2019 12:30
Show Gist options
  • Save rhlmalik17/5198778c1c323c1471e4281f61bddfc5 to your computer and use it in GitHub Desktop.
Save rhlmalik17/5198778c1c323c1471e4281f61bddfc5 to your computer and use it in GitHub Desktop.
//None of the conditions are executing even if its actually true.
import java.io.*;
import java.util.*;
class set2Question4
{
static public int EvenOddDigitsSum(int input1,String input2)
{
int sum=0,temp,i=0,num=0;
if(input2=="even")
{
temp=input1;
while(temp!=0)
{
num=temp%10;
if(temp%2==0)
{
sum+=num;
}
temp=temp/10;
}
}
else if(input2=="odd")
{
temp=input1;
while(temp!=0)
{
num=temp%10;
if(temp%2!=0)
{
sum+=num;
}
temp=temp/10;
}
}
return sum;
}
public static void main(String args[])
{
Scanner taker = new Scanner(System.in);
int num;
String type;
num = taker.nextInt();
type=taker.nextLine();
System.out.print(EvenOddDigitsSum(num,type));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment