Write a JAVA program to find summation of individual digits of given number ? | IMP java programs|code-01 | StudyEcart

 Q. Write a JAVA program to find the summation of individual digits of a given number?

package impprograms;

import java.util.Scanner;

public class Code23 {

	public static void main(String[] args) {
    
    int sum=0;
	Scanner scan=new Scanner(System.in);
    System.out.println("Please Enter a Number :");
	int val=scan.nextInt();
 
	while(val!=0) {
     int temp=val%10;
     sum=sum+temp;
     val=val/10;
	}
	
 System.out.println(" \n *** sum of individual Digits of given number is : "+sum);
 scan.close();
	}


Note: you can drag the code workspace to see the complete code

Post a Comment

0 Comments