I'm trying to add elements to two arrays. I declared the double arrays so that they also accept decimal numbers.
I am getting 7 elements from the user and add them. If the user only gives 6 elements instead of 7 elements, it waits until the 7th element is given.
If the user gives only 6 elements instead of giving 7, it has to take the position of 7th element as "0" and add the elements and print the sum. It cannot wait for the 7th element. For that what can i do?
Scanner in = new Scanner(System.in);
double a[] =new double[100];
double b[] =new double[100];
double suma=0,sumb=0;
for(int i=0;i<7;i++)
{
a[i]=in.nextDouble();
suma=suma+a[i];
}
for(int i=0;i<7;i++)
{
b[i]=in.nextDouble();
sumb=sumb+b[i];
}