Write a program to create two SDA to store 15 numbers each. Then create another array to store their sum. Then display values of three arrays in three different consecutive columns.
For example:
10 + 7 = 17
18 + 30 = 48
Where first column represents first array, second column represents second array and third column represents values of third array.
import java.util.Scanner;
public class App {
/**
* The start point of the program
*
* @param args
*
*/
public static void main(String[] args) {
Scanner keyBoard = new Scanner(System.in);
int numbers1[] = new int[15];
int numbers2[] = new int[15];
int sum[] = new int[15];
System.out.println("Enter the numbers for the first array:");
for (int i = 0; i < 15; i++) {
System.out.print("Enter the number " + (i + 1) + ": ");
numbers1[i] = keyBoard.nextInt();
}
System.out.println("\nEnter the numbers for the second array:");
for (int i = 0; i < 15; i++) {
System.out.print("Enter the number " + (i + 1) + ": ");
numbers2[i] = keyBoard.nextInt();
}
for (int i = 0; i < 15; i++) {
sum[i] = numbers1[i] + numbers2[i];
}
System.out.println("");
for (int i = 0; i < 15; i++) {
System.out.printf("%-5d + %-5d = %-5d\n", numbers1[i], numbers2[i], sum[i]);
}
keyBoard.close();
}
}
Comments
Leave a comment