Question: public static double fractionSum(int n) { double sum = 0; for (int i = 1; i Solution 1 public static int wordCount(String s) {

public static double fractionSum(int n) { double sum = 0; for (inti = 1; i Solution 1 public static int wordCount(String s) {int count = 0; for (int i = 0; i < s.length()

public static double fractionSum(int n) { double sum = 0; for (int i = 1; i Solution 1 public static int wordCount(String s) { int count = 0; for (int i = 0; i < s.length() - 1; i++) { if(s.charAt(i) count++; == && s.charAt(i+1) != ') { if(s.charAt(0) != ') { count++; } } } } return count; Solution 2 public static int wordCount(String s) { int count = 0; char prevChar = s.charAt(0); for (int i=1; i < s.length(); i++) { char curChar = s.charAt(i); if (prevChar count++; == && curChar = '') { } prevChar = curChar; } if (s.charAt(e) != ') { count++; return count; } } public static int digitSum(int num) { num = Math.abs(num); int sum = 0; while(num > 0) { sum += (num % 10); num /= 10; } return sum; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!