Java program to find the odd or even in the box challenge

Java program to find the odd or even in the box challenge. The numbers in the input must be bigger than zero. Otherwise, print “is not a valid input” and exit. Print “is even it’s a valid box” if the sum is even.If the sum is odd, print “is odd, this box is invalid.” If the box contains balls that are less than zero, print “is not a valid input.” Please do not terminate the program with System.exit.

import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("The box contains");
int num = sc.nextInt();
if(num<0)
{
System.out.println(num+" is not a valid input");
return;
}
else{
System.out.println("Enter the number");
int arr[] = new int[num];
int sum =0;
for (int i=0;i<num;i++)
{
int a = sc.nextInt();
if(a>0){
arr[i] = a;
sum += (arr[i]%10);
}
else{
System.out.println(a+" is not a valid input");
}
}

if(sum%2==0){
System.out.println(sum+" is even its valid box");
}
else {
System.out.println(sum+" is odd its invalid box");
}

}
}
}

 

Output:

The box contains
2
Enter the number
45
56
11 is odd its invalid box