Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PLEASE HELP!!!I need help with the following JAVA PROGRAMS. So this comes from t

ID: 3738017 • Letter: P

Question

PLEASE HELP!!!I need help with the following JAVA PROGRAMS. So this comes from tony gaddis starting out with java book. I have included the screenshot of the problems for reference. I need HELP implementing these two problems TOGETHER. There should be TWO class files. One which has TWO methods (one to implement problem 8, and one to implement problem 9). The second class should consist of the MAIN program with the MAIN method which calls those methods. Thank you in advance!!! Please let me know if you would like any clarification!!! ALSO please include comments if possible so I can understand better.

8. Sum of Numbers in a String Write a program that asks the user to enter a series of numbers separated by commas. Here is an example of valid input: 7,9,10,2,18,6 The program should calculate and display the sum of all the numbers. 9. Sum of Digits in a String Write a program that asks the user to enter a series of single digit numbers with nothing separating them. The program should display the sum of all the single digit numbers in the string. For example, if the user enters 2514, the method should return 12, which is the sum of 2, 5, 1, and 4. The program should also display the highest and lowest digits in the string. (Hint: Convert the string to an array.)

Explanation / Answer

SumOfNumbersWithComma.java

import java.util.Scanner;

public class SumOfNumbersWithComma {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

System.out.println("Enter the numbers separated by comma:");

String s = scan.next();

String n[]=s.split(",");

int sum = 0;

for(int i=0;i<n.length;i++) {

sum+=Integer.parseInt(n[i]);

}

System.out.println("Sum: "+sum);

}

}

Output:

Enter the numbers separated by comma:
7,9,10,2,18,6
Sum: 52

SumStringNumbers.java

import java.util.Scanner;

public class SumStringNumbers {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

System.out.println("Enter the number: ");

String s = scan.next();

char ch[]= s.toCharArray();

int sum = 0;

int min = ch[0]-'0';

int max = ch[0]-'0';

for(int i=0;i<ch.length;i++) {

sum = sum + (ch[i]-'0');

if(max < (ch[i]-'0'))

max = (ch[i]-'0');

if(min > (ch[i]-'0'))

min = (ch[i]-'0');

}

System.out.println("Sum: "+sum);

System.out.println("Max: "+max);

System.out.println("Min: "+min);

}

}

Output:

Enter the number:
2514
Sum: 12
Max: 5
Min: 1

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote