I am completely new to java and am very lost on a current program I am working on. I cannot figure out what code to add in or use when it comes to extracting the digits using an operator.
Here is my instructions:
Write a program that reads an integer from 0 to 999 from the keyboard and then adds up all the digits in the integer. For example, if the integer is 735 then the sum of the digits is 7+3+5=15.
(This is the current code I have so far) Any help is appreciated.
1 import java.util.Scanner; 2 /** 3 * 4 * @author willkellogg 5 */ 6 public class SumDigits { 7 public static void main(String[] args) { 8 Scanner input = new Scanner(System.in) ; 9 10 //input 11 System.out.println("Enter a number from 0 to 999: ") ; 12 double digit1 = input.nextDouble() ; 13 double digit2 = input.nextDouble() ; 14 double digit3 = input.nextDouble() ; 15 16 //process 17 double average = (digit1 + digit2 + digit3) / 3 ; 18 19 20 //output 21 System.out.println("The sum of the digit is " + digit1 + "" + digit2 + "" 22 + digit3 + "is" + average) ; } }