Ready For Your Exams









What's the answer for "Sum of Digits" in Java ?

Posted by: 1 | Subject: Programming | Date: 2024-10-06 13:26:33

Answers:

import java.util.*;

public class Main {

public static int sumOfDigits(String n) {

if (n.length() == 1) {
return Character.getNumericValue(n.charAt(0));
}

return Character.getNumericValue(n.charAt(0)) + sumOfDigits(n.substring(1));
}



public static void main(String[] args) {
// Enter your code here
Scanner scanner = new Scanner(System.in);
String input = scanner.nextLine();

// Calculate and print the sum of digits using recursion
int result = sumOfDigits(input);
System.out.println(result);
scanner.close();
}
}

Date: 2024-10-06 13:26:57



What is 10 - 6 ?

Posted by: 1 | Subject: Maths | Date: 2024-09-23 09:16:45

Answers:

Correct answer is 4

Date: 2024-09-23 09:17:59



What is 10/2 ?

Posted by: 3 | Subject: Maths | Date: 2024-08-19 11:29:03

Answers:

Answer is 5

Date: 2024-08-19 13:08:06



What is Al ?

Posted by: 1 | Subject: Chemistry | Date: 2024-08-14 16:37:50

Answers:

Its a metal

Date: 2024-08-19 11:28:28