Computer Science, asked by anuragmirbahar, 1 year ago

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 sswaraj04
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
sswaraj04: i can't write mine state
sswaraj04: is it really offensive..
anuragmirbahar: why
sswaraj04: your poor neighbour
sswaraj04: try writing it
anuragmirbahar: it's quite easy for me
sswaraj04: now i really want to know y i can't write my state name
sswaraj04: i need to ask brainly for it
sswaraj04: leave it if u have any doubt u can ask for sure
Similar questions