Computer Science, asked by saireddypappireddy, 5 months ago

2. Take 20 integer inputs from user and print the following:
number of positive numbers
number of negative numbers
number of odd numbers
number of even numbers
number of Os.​

Answers

Answered by BrainlyProgrammer
15

Answer:

import java.util.*;

class number

{

public static void main ( String ar [])

{

Scanner sc=new Scanner (System.in);

int n,I,p=0,c=0,o=0,e=0,z=0;

for(I=1;I<=20;I++);

{

System.out.println("Enter a number");

n=sc.nextInt();

if (n>0)

p++; //count of positive no's.

if (n<0)

c++; //count of negative no's.

if (n%2==0)

e++; //count of even no's.

if (n%2!=0)

o++; //count of odd no's

if (n==0)

z++; //count of zeros

}

System.out.println("number of positive numbers"+p);

System.out.println("number of negative numbers"+c);

System.out.println("number of odd numbers"+o);

System.out.println("number of even numbers"+e);

System.out.println("number of zeroes"+z);

}

}

Answered by anindyaadhikari13
8

Answer:-

This is the required program for this question.

import java.util.*;

class Number

{

public static void main(String x[])

{

Scanner sc=new Scanner(System.in);

System.out.println("Enter 20 numbers...");

int a[] ={0,0,0,0,0};

for(int i=1;i<=20;i++)

{

int x=sc.nextInt();

if(x>0)

a[0]=a[0]+1;

if(x<0)

a[1]=a[1]+1;

if(x==0)

a[4]=a[4]+1;

if(x%2==1)

a[2]=a[2]+1;

else

a[3]=a[3]+1;

}

System.out.println("Number of positive numbers: "+a[0]);

System.out.println("Number of negative numbers: "+a[1]);

System.out.println("Number of odd numbers: "+a[2]);

System.out.println("Number of even numbers: "+a[3]);

System.out.println("Number of zeros: "+a[4]);

}

}

Similar questions