148k views
2 votes
Write a (java) program with a class called Sum1, using a while loop to add 10 numbers entered from the key-board.

Hint

the program has three variables

1- number

2- sum

3- count

User Dhina K
by
7.7k points

1 Answer

1 vote

This is a java program with a class called Sum1.

Step-by-step explanation:

While loop is used to add 10 number.

import java.util.Scanner;

public class Sum 1

{

public static void main(String args[])

{

int number, count, sum = 0;

Scanner s = new Scanner(System.in);

System.out.print("Enter the number:");

number = s.nextInt();

while(number > 0)

{

count = number % 10;

sum = sum + n;

number = number / 10;

}

System.out.println("Sum of Digits:"+sum);

}

}

User Joachim Schork
by
8.5k points

Related questions

asked Apr 23, 2024 199k views
Mdcarter asked Apr 23, 2024
by Mdcarter
8.0k points
1 answer
4 votes
199k views
asked May 2, 2024 56.1k views
Michalsrb asked May 2, 2024
by Michalsrb
8.0k points
1 answer
5 votes
56.1k views