Answer:
Following are the correct code to this question:
import java.util.*;//import package
public class QuestionNumber4 //defining class QuestionNumber4
{
public static void main(String[] args)//defining the main method
{
int countValidNumber=0,n=0;//defining integer varaible
int num[]= new int[100]; //defining integer array num
Scanner ob=new Scanner(System.in);//creating Scanner class Object
try //using try block
{
for(int i=0;i<100;i++)//defining loop to input 100 values
{num[i]=ob.nextInt();//input value in array
n=n+num[i];//add number
countValidNumber++;//count input value
if(n<0){}}//defining if block to check another value
}
catch(Exception e) //catch block to handle Exception
{
System.out.println("input is not valid");// print message
}
System.out.println("total intered number are: " + countValidNumber);//print times of input value
}
}
Output:
2
5
7
9
o
input is not valid
total intered nyumber are: 4
Explanation:
following are the description of the above code: