forked from txs72/JavaTutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCh02Q06.java
More file actions
executable file
·27 lines (25 loc) · 852 Bytes
/
Ch02Q06.java
File metadata and controls
executable file
·27 lines (25 loc) · 852 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/* */ package ch02;
/* */
/* */ import java.util.Scanner;
/* */
/* */ public class Ch02Q06 {
/* */ public static void main(String[] args) {
/* 7 */ Scanner scanner = new Scanner(System.in);
/* 8 */ System.out.print("Enter a number between 0 and 1000: ");
/* 9 */ int number = scanner.nextInt();
/* 10 */ if (number <= 0 || number >= 1000) {
/* 11 */ System.out.println("Number invalid.");
/* 12 */ System.exit(1);
/* */ }
/* 14 */ int sum = 0;
/* 15 */ while (number != 0) {
/* 16 */ sum += number % 10;
/* 17 */ number /= 10;
/* */ }
/* 19 */ System.out.println(sum);
/* */ }
/* */ }
/* Location: /Volumes/TXS.128G/hope useful/practice/2020.jar!/ch02/Ch02Q06.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/