OOP Lab 02 Loop, Array and Methdos
OOP Lab 02 Loop, Array and Methdos
Method sumDigits (int number) returns the sum of all digits in number.
In the main method, prompt the user for an integer input and pass the input to method sumDigits()
to obtain the sum of its digits. Then display the entered number followed by the sum of its digits
as shown below. Document your code and properly label the input prompt and the outputs as
shown below.
Sample run 1:
You entered: 12345
Sum of digits: 15
2. method to reverse the digits of number
3. method to count the number of digits of a number
Loop Related Questions:
1. Write a Java program Using for loop and while loop that will display the word “Hello
World” 50 times on the screen in new line.
2. Write a Java program using for loop that asks the user to enter a number ‘N’ from the
keyboard and then prints all numbers from 1 to N separated by space in one row on the
screen. For example: if the number is 3, the output is 1 2 3 and if the number is 5, the
output is 1 2 3 4 5
4. program to find the sum of numbers from 1 to n.
Arrays Related Questions:
1. Write a java program that prompts the user to reads ten integers from the keyboard and
displays them in the reverse of the order in which they were read.
Smaple output