I wrote this program to ask the user to give a series of numbers and then our program will sum up all the numbers using Java as my programming language.
I am currently accepting programming and web development work kindly contact me in the following email address for further details. Thank you.
My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.
My telephone number at home here in Bacolod City, Negros Occidental Philippines is +63 (034) 4335675.
Sample Program Output
Program Listing
sum.java
import java.util.Scanner;
class sum {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Sum of a Number in Java");
System.out.print("\n\n");
System.out.print("Created By Mr. Jake R. Pomperada");
System.out.print("\n\n");
System.out.print("Give a Number : ");
int n = input.nextInt();
int number = n;
int sum = 0;
int num = number;
while (num > 0) {
int lastDigit = num % 10;
sum += lastDigit;
num /= 10;
}
System.out.print("\n\n");
System.out.println("Sum of digits is "+sum +".");
System.out.print("\n\n");
}
}
No comments:
Post a Comment