IGNOU - MCSL025 - SECTION04 - [S02_E02]

♠ Posted by Unknown in , at 06:50

IGNOU - MCSL025 - SECTION04 - [S02_E02]

/*Author: Viral Vyas
 * Write a program in Java to compute the sum of the digits of a given integer.
 * Remember, your integer should not be less than the five digits.
 */
package mcsl025;
import java.io.*;
import java.lang.*;

public class S02E02 {
    public static void main(String[] args) throws IOException{


        int rem, sum=0;
        BufferedReader br = new BufferedReader(
                new InputStreamReader(System.in));
        
        System.out.print("Enter Any Integer Number : ");
        int n = Integer.parseInt(br.readLine());
                
        System.out.print("The Reverse No : ");
        while(n != 0){
            rem = n % 10;            
            System.out.print(rem);
            sum = sum + rem;
            n = n / 10;
        }
        
        System.out.println("\nThe Sum of digits : " + sum);
    }
}

Output:
Enter Any Integer Number : 1234
The Reverse No : 4321
The Sum of digits : 10


0 comments:

Post a Comment