Q.Write a java program to count the number of integers from a given list. (Use Command line arguments). [15 M]
public class CountIntegers
{
public static void main(String args[])
{
int count = 0;
for(int i = 0; i < args.length; i++)
{
try
{
Integer.parseInt(args[i]); // check if integer
count++;
}
catch(NumberFormatException e)
{
// ignore non-integer values
}
}
System.out.println("Number of integers = " + count);
}
}
