package eecs1022.finalc; /** * This question is worth 2.5 marks. No partial marks will be awarded for this question. * * @author Franck van Breugel */ public class Question6 { /** * Returns the product of the digits occurring in the given string. You may assume that * the string is not null and contains at least one digit. * * @param s a string. * @return the product of the digits occurring in the given string. */ public static int product(String s) { int product = 1; for (int i = 0; i < s.length(); i++) { char letter = s.charAt(i); if (letter >= '0' && letter <= '9') { int number = letter - '0'; product = product * number; } } return product; } /** * Tests method. You may add more test cases. * * @param args not applicable. */ public static void main(String[] args) { System.out.println(Question6.product("1234")); System.out.println(Question6.product("1a5h5x1")); System.out.println(Question6.product("12h56s9")); System.out.println(Question6.product("aaaaaa4aaaaa")); System.out.println(Question6.product("5a")); } }