Wednesday, March 30, 2011

P7.1

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package p71;

import java.util.Scanner;

/**
 *
 * @author student
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {


        Scanner scanner = new Scanner(System.in);
        System.out.print("How many digits in the BIGGER number? (must be 50 or less): ");
        int n = scanner.nextInt();


        double[] num1 = new double[n];

        double[] num2 = new double[n];

        System.out.println("Enter the digits from SMALLEST to LARGEST.\nDigits must be between 0 and 99.");

        int i;
        for (i = 0; i < n; i++) {
          Scanner in = new Scanner(System.in);
          System.out.print("Enter a digit: ");
          num1[i] = in.nextDouble();
        }

        System.out.println("Now enter the digits in the SMALLER NUMBER from SMALLEST to LARGEST. \nUse the same number of digits as the larger number; \nEnter 0 if the value of that digit is zero.\n(Ex. Larger number: 5004, Smaller number: 312. \nEnter 2, 1, 3, 0 for the smaller number.) ");

        int j;
        for (j = 0; j < n; j++) {
          Scanner in = new Scanner(System.in);
          System.out.print("Enter a number in the array: ");
          num2[i] = in.nextDouble();
        }

        double[] sum = new double[n];

        int k;
        for (k=1; k <= n; k++) {
          sum[k] = num1[k] + num2[k];
        }

        System.out.println("Sum = " + sum + "\n(Ex. if sum = [1, 13, 0, 0, 1],\nthen the sum is 23,001.)");


    }

}

No comments:

Post a Comment