-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay-03-Java-Q13
More file actions
51 lines (35 loc) · 1.14 KB
/
Copy pathDay-03-Java-Q13
File metadata and controls
51 lines (35 loc) · 1.14 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*Sanjay wants to learn the calculation of integer digits.could you please help him to implements the sum of digits in programming. Notes:- - If the integer is 45,separate the each digits (4+5) the output is 9.
Input Format
input consists of one integer.
Constraints
Given N is greater than 9 and lesser than 99
Output Format
execute the sum of digits values. Notes:-
If the input is above 100, execute the statements is "Invalid Input".
Sample Input 0
23
Sample Output 0
Sum of Digit 23 is 005
Sample Input 1
56
Sample Output 1
Sum of Digit 56 is 011
Sample Input 2
100
Sample Output 2
Invalid Input*/
#Answer
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
System.out.printf((num > 9 && num < 100)
? "Sum of Digit %d is %03d"
: "Invalid Input",
num, (num > 9 && num < 100) ? (num / 10 + num % 10) : 0);
sc.close();
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
}
}