Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Aravind's teacher gives him an assignment on the topic array. He got two arrays as input, and in those he has to add the elements

Aravind's teacher gives him an assignment on the topic "array." He got two arrays as input, and in those he has to add the elements of both arrays and store them in a new array, and then only add the last digits of all elements from the third array and store them in a new variable and check if it is a prime number or not. Help Aravind complete his assignment using Java.
Requirements:
If both the array size is not the same, print "Both array size is different" then terminate the program.
If the size is less than or equal to zero, print " is an invalid array size" then terminate the program.
If the elements entered in an array have a value less than zero, print " is an invalid input" and then terminate the program.
Note:
In the Sample Input / Output provided, the highlighted text in bold corresponds to the input given by the user, and the rest of the text represents the output.
Ensure to follow the object-oriented specifications provided in the question description.
Ensure to provide the names for classes, attributes, and methods as specified in the question description.
Adhere to the code template, if provided
Please do not use System.exit(0) to terminate the program.
Sample input/Output1:
Enter the size of first array
4
Enter the array elements
2
3
4
5
Enter the size of second array
4
Enter the array elements
6
6
6
6
18 is not a prime number
Explanation
Array1={2,3,4,5}
Array2={6,6,6,6}
add the integers in the two arrays -> Array1[0]+ Array2[0]= Array3[0]
2+6=8
3+6=9
4+6=10
5+6=11
Array3={8,9,10,11}
In a new variable only add last digits in a Array[3]
8+9+0+1=18
Check 18 for prime number
Hence 18 is not a prime number
Sample input/output2:
Enter the size of first array
2
Enter the array elements
0
23
Enter the size of second array
2
Enter the array elements
23
25
11 is a prime number
Explanation
Array1={0,23}
Array2={23,25}
add the integers in the two arrays -> Array1[0]+ Array2[0]= Array3[0]
0+23=23
23+25=48
Array3={23,48}
In a new variable only add last digits in a Array[3]
3+8=18
Check 11 for prime number
Hence 11 is a prime number
Sample input/Output3:
Enter the size of first array
-2
-2 is an invalid array size
Sample input/Output4:
Enter the size of first array
3
Enter the array elements
1
2
3
Enter the size of second array
-2
-2 is an invalid array size
Sample input/Output5:
Enter the size of first array
2
Enter the array elements
-3
-3 is an invalid input
Sample input/Output6:
Enter the size of first array
1
Enter the array elements
23
Enter the size of second array
2
Both array size is different

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Administration The Complete Guide To Dba Practices And Procedures

Authors: Craig S. Mullins

2nd Edition

0321822943, 978-0321822949

More Books

Students also viewed these Databases questions

Question

2. Outline the functions of nonverbal communication

Answered: 1 week ago