Computer Science, asked by arnav9688, 5 months ago

Convert the following while into a for loop.

public void sum (int n) {

int s=0;

while(n>0) {

s=s+n%10;

n/=10; }

System.out.println(“Sum of digits = “+s);​

Answers

Answered by digitechnta
2

Answer:

public void sum (int n)

{

int s=0;

for(int n=1;n>0;n/=10)

{

s=s+n%10;

}

System.out.println(“Sum of digits = “+s);

Similar questions