repl.it
@Brawn/

Mastery Project #3B Code #2

Java

No description

fork
loading
Files
  • Main.java
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
Name: Allan Abraham
Purpose: Adds all the digits of the number that is
inputted
*/

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		System.out.println("Type the number in!");
		int num = input.nextInt();
		int sum = 0;
		while(num > 0){
			sum += (num % 10);
			num /= 10;
		}
		System.out.print(sum);
	}
}
?