b) Input an integer number (num) and print the sum of only those digits of the number which are multiples of 2 or3.Sample input: num=43961 Sample output : sum = 4 + 3 +9 +6 = 22
Answers
Answer:
it's cool and the playlist on the link
here the
input: num=43961
output : sum = 4 + 3 +9 +6 = 22
Explanation:
public class abc
{
public int Sum(int A, int B) {
int sum = 0;
for (int i = A; i <= B; i++) {
if (i % 2 == 0)
sum += i;
}
return sum;
}
public double Sum(double N) {
double p = 1.0;
for (double i = 1.0; i <= N; i += 0.2)
p *= i;
return p;
}
public int Sum(int N) {
int sum = 0;
while (N != 0) {
int d = N % 10;
if (d % 2 != 0)
sum += d;
N /= 10;
}
return sum;
}
public static void main(String args[]) {
abc obj = new abc();
int evenSum = obj.Sum(4, 16);
System.out.println("Even sum from 4 to 16 = " + evenSum);
double seriesProduct = obj.Sum(2.0);
System.out.println("Series Product = " + seriesProduct);
int oddDigitSum = obj.Sum(43961);
System.out.println("Odd Digits Sum = " + oddDigitSum);
}
}