Aim:- Write a program,
which takes five numbers as command line argument from user, store them in
one-dimensional array and display count of negative numbers.
JAVA Code :-
import java.lang.*;
class TestArray
{
public static void main(String[] args)
{
int c=0;
int a[]=new int[5];
for(int i=0;i<5;i++)
{
a[i]=Integer.parseInt(args[i]);
if(a[i]<0)
c++;
}
System.out.println("No. of negtive
number: " +c);
}
}
Output:-
No comments:
Post a Comment