/home/caleb/ASDV-Java/MP1_CalebFontenot/src/main/java/com/calebfontenot/mp1_calebfontenot/SumOfDigits.java |
package com.calebfontenot.mp1_calebfontenot;
@author
public class SumOfDigits {
public static void main(String[] args)
{
java.util.Scanner input = new java.util.Scanner(System.in);
System.out.print("Inter an integer between 0 and 1000: ");
int number = input.nextInt();
int lastDigit = number % 10;
int remainingNumber = number / 10;
int secondLastDigit = remainingNumber % 10;
remainingNumber = remainingNumber / 10;
int thirdLastDigit = remainingNumber % 10;
int sum = lastDigit + secondLastDigit + thirdLastDigit;
System.out.println("The sum of all digits in "+ number
+ " is " + sum);
}
}