|
[b]Hi All, I am summing the numbers, then need to print each number on a seperate line. For instance if i input 1234 on each separate line it should add it, give the total such as 10, then print 1 2 3 4
I am getting 2 of the numbers to print correctly. Can someone help me please. I also have to do one in ascending order.
Code is
import java.util.*; public class sumspg296 { static Scanner console = new Scanner(System.in); public static void main (String[] args) { // Program to ask user to input digits returns the digits and sums */ int num, temp, sum, ans; System.out.print("Enter A Number: "); num = console.nextInt(); ans = num % 10; System.out.println(); temp = num; sum = 0; do { sum = sum + num % 10; num = num / 10; } while (num >= 0); System.out.println("The sum of the numbers = " + sum); num = num / 10; ans = num % 10; System.out.println(" " + ans); num = num / 10; ans = num % 10; System.out.println(" " + ans);
} }
Thanks
|