Use loop(s)
Must be in Java
Java code:
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner input=new
Scanner(System.in);
//initializing number and sum
int num,sum=0;
//asking for
number
System.out.print("Enter
a 5 digit positive integer: ");
//accepting it
num=input.nextInt();
//looping for 5
iteration
for(int
i=0;i<5;i++){
//adding last digit of number to sum
sum+=num%10;
//removing last digit from number
num=num/10;
}
//printing the sum
System.out.println("Sum="+sum);
}
}
Screenshot:
Input and Output:
Get Answers For Free
Most questions answered within 1 hours.