Monday 9 June 2014

Program to add all the digits of a three digit number

// this program adds all the digits of a three digit number
import javax.swing.*;
public class add
{ public static void main(String[] args)
                      {
int a1,a2,a3,rev,n;
n=Integer.parseInt(JOptionPane.showInputDialog("enter the no"));
a1=n%10;
n=n/10;
a2=n%10;
n=n/10;
a3=n%10;
rev=a1+a2+a3;
System.out.print("sum of digits is "+rev);

}
}
output:
enter the no 123
sum of digits is 6

No comments:

Post a Comment

SAY HELLO!!