TASK-1 Design a command-line calculator that can perform basic
arithmetic operations (+, -, *, /) on two numbers. The twist: it
should be able to handle
both integer and floating-point inputs, and if a non-numeric
argument is
provided, it should gracefully inform the user. The program should
use Wrapper Classes for internal number representation and
Autoboxing/Unboxing during calculations.
Example Usage:
java Calculator 10 + 5 (Output: 15)
java Calculator 10.5 * 2 (Output: 21.0)
java Calculator hello + world (Output: Error: Invalid numeric input.)
TASK-2 Program to find if the given numbers are Friendly pair or not
(Amicable or not). Friendly Pair are two or morenumbers with a
common abundance.
Input & Output format:
Input consists of 2 integers.
The first integer corresponds to number 1 andthe
second integer corresponds to number 2.
If it is a Friendly Pair display Friendly Pair or displays Not Friendly
Pair.
2. For example,6 and 28 are Friendly Pair. 2
(Sum of divisors of 6)/6 = (Sum of divisors of 28)/28.
Steps to check whether the given numbers are friendly pair or not
Input the numbers num1 and num2.
Initialize sum1 = sum2 = 0.
sum1 = sum of all divisors of num1.
sum2 = sum of all divisors of num2.
If (sum1 == num1) and (sum2 == num2),
then print "Abundant Numbers".
Else, print "Not Abundant Numbers".
Program to check whether the given numbers are friendly pair or
not
Array in Java:
TASK-3
Printing an array into Zigzag fashion. Suppose youwere given an
array of integers, and you are told to sort the integers in a zigzag
pattern. In general, in a zigzag pattern, the first integer is less than
the second
integer, which is greater than the third integer, which is less than
3. the fourth integer, and so on. Hence, the converted array should be 2
in the form of e1 < e2 > e3 < e4 > e5 < e6.
Test cases: Input 1:
7
4378621
Output 1:
3748261
Input 2:
4
1432
Output 2:
1423
The problem to rearrange positive and negative numbers in an array
TASK-4 .
Method: This approach moves all negative numbers to the
beginning and positive numbers to the end butchanges the order
of appearance of the elements of the array.
Steps:
4. 2
1. Declare an array and input the array elements.
2. Start traversing the array and if the current element is
negative, swap the current elementwith the first
positive element and continue traversing until all the
elements have been encountered.
3. Print the rearranged array.
Test case:
Input: 1 -1 2 -2 3 -3 Output: -1 -2 -3 1 3 2
Program to find the saddle point coordinates in a given matrix. A
TASK-5 saddle point is an element of the matrix,which is the minimum
element in its row and the maximum in its column.
For example, consider the matrix given
belowMat [3][3] 1 2 3
456
789
5. Here, 7 is the saddle point because it is the minimum element in its 2
row and maximum element in its column.
Steps to find the saddle point coordinates in a givenmatrix.
1. Input the matrix from the user.
2. Use two loops, one for traversing the row andthe
other for traversing the column.
3. If the current element is the minimum element inits
row and maximum element in its column, then
return its coordinates.
Else, continue traversing.