/home/caleb/ASDV-Java/MP1_CalebFontenot/src/main/java/com/calebfontenot/mp1_calebfontenot/SumOfDigits.java
/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package com.calebfontenot.mp1_calebfontenot;

/**
 *
 * @author caleb
 */
public class SumOfDigits {
    public static void main(String[] args)
    {
        java.util.Scanner input = new java.util.Scanner(System.in);
        //> Read a number
    System.out.print("Inter an integer between 0 and 1000: ");
    int number = input.nextInt();
    
        //> Find all digits in number
    int lastDigit = number % 10;
    int remainingNumber = number / 10;
    int secondLastDigit = remainingNumber % 10;
    remainingNumber = remainingNumber / 10;
    int thirdLastDigit = remainingNumber % 10;
    
        //> Obtain the sum of all digits
    int sum = lastDigit + secondLastDigit + thirdLastDigit;
    
        //>Display results
        System.out.println("The sum of all digits in "+ number
        + " is " + sum);
    }
    
}