Advertisement
Shailrshah

Command Line Input to Find Sum of Cube of Digits

Aug 24th, 2013
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.44 KB | None | 0 0
  1. import java.io.*;
  2. class CommandLineInput{
  3.     static public void main (String[] args){
  4.         int no = Integer.parseInt(args[0]);
  5.         int sum = 0;
  6.         while(no != 0){
  7.                 int remainder = no % 10;
  8.                     sum += remainder * remainder * remainder;
  9.                     no /= 10;
  10.             }
  11.         System.out.print("Sum of cube of individual digits = "+sum);       
  12.     }
  13. }
  14.  
  15. // Output:-
  16. // C:\Java>java CommandLineInput 23
  17. // Sum of cube of individual digits = 35
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement