تم الحل ✓
categoryبرمجة وتطوير البرمجيات
schoolبكالوريوس
event_available2026-07-14
السؤال
Transcribed Image Text:
1- Write a recursive method int mul(int a, int b) that computes the product of two nonnegative
integers a and b. You are not allowed to use multiplication (*).
Hint: use addition (+) and recursion.
2- Write a method evenDigits that accepts an integer parameter n and that returns the integer formed
by removing the odd digits from n. The following table shows several calls and their expected return
values:
Call
Valued Returned
evenDigits (8342116); 8426
evenDigits (4109);
40
evenDigits (8);
8
evenDigits (-34512);
-42
evenDigits (-163505);
-60
evenDigits (3052);
2
evenDigits (7010496); 46
evenDigits (35179);
0
evenDigits (5307);
0
evenDigits (7);
If a negative number with even digits other than 0 is passed to the method, the result should also be
negative, as shown above when -34512 is passed. Leading zeros in the result should be ignored and
if there are no even digits other than 0 in the number, the method should return 0, as shown in the
last three outputs.
check_circle الجواب — حل مفصل خطوة بخطوة
hourglass_top
🔒
الحل الكامل متاح للمشتركين
اشترك في أرشيف الأسئلة لعرض هذا الحل وآلاف الحلول المفصلة خطوة بخطوة من معلمين معتمدين.