Instantly share code, notes, and snippets.

Embed
What would you like to do?
CSC-111 Starter Code for In-class Sum Digits Challenge
import java.util.Scanner;
public class SumDigits {
public static void main(String[] args) {
System.out.println("Welcome to the Sum Digits Solver!");
Scanner input = new Scanner(System.in);
int number;
do {
System.out.print("Enter a positive number: ");
number = input.nextInt();
if (number < 0)
System.out.println("Come on pheeb. Enter a positive number!");
} while (number < 0);
// Now enter your code here to calculate the sum of the digits in number
// i.e. number = 2347 Sum of Digits = 16
input.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment