write a program in blue j with if else and buffered reader which will accept a two digit number and find the sum of its digit
For eg. Sample Input=56
Sum of digits=11
Answers
Answered by
4
Answer:
import java.io.*;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int val = Integer.parseInt(br.readLine());
if(val<100&&val>9)
{
int n=val/10+val%10;
System.out.println("Sum of digits is "+n);
}
else
System.out.println("Wrong input");
}
}
Explanation:
if number lies between 10 and 100
then we need to find it's ones place and tens place digit
ones place digit can be find by modulus operator and tens place can be find by dividing by 10
and sum of digits will be sum of these two
e.g 56
56%10=6
56/10=5
sum of digit=5+6=11
% returns remainder on dividing by some given value
Hope it helps :-)
sswaraj04:
west bengal
Similar questions
Physics,
6 months ago
Science,
6 months ago
Physics,
1 year ago
Psychology,
1 year ago
Geography,
1 year ago