/* * Withdrawal : Computes a simple balance. * Asks user for number of entries, positive and negative integers. * App sums up the positives (deposits) and the negatives (withdrawals) * and reports the sum for both. * * Parke Godfrey * 2009 October 20 */ import java.io.PrintStream; import java.util.Scanner; public class Withdrawal { public static void main(String[] args) { PrintStream output = System.out; Scanner input = new Scanner(System.in); output.println("Enter # of integers to add:"); int numberOfIntegersToAdd = input.nextInt(); long deposit = 0; long withdrawal = 0; int i = 1; while (i <= numberOfIntegersToAdd) { output.println("Enter integer #" + i + ":"); long x = input.nextLong(); if (x < 0) { withdrawal += x; } else { deposit += x; } i++; } output.println("The deposits sum to " + deposit + "."); output.println("The withdrawals sum to " + withdrawal + "."); } }