Computer Science, asked by shruti13845, 5 months ago

wap in java to print the total number of positive and negative integers upto n terms ​

Answers

Answered by pandeysuman70507
2

Answer:

This program allows the user to enter the size, and the One Dimensional Array elements. Next, it will count the total number of positive and negative numbers within this array using For Loop.

Explanation:

Java Program to Count Positive and Negative Numbers in an Array

import java.util.Scanner;

public class CountPositiveNegative1 {

private static Scanner sc;

public static void main(String[] args)

{

int Size, i;

int positiveCount = 0, negativeCount = 0;

sc = new Scanner(System.in);

System.out.print(" Please Enter Number of elements in an array : ");

Size = sc.nextInt();

int [] a = new int[Size];

System.out.print(" Please Enter " + Size + " elements of an Array : ");

for (i = 0; i < Size; i++)

{

a[i] = sc.nextInt();

}

for(i = 0; i < Size; i++)

{

if(a[i] >= 0)

{

positiveCount++;

}

else

{

negativeCount++;

}

}

System.out.println("\n Total Number of Positive Numbers in this Array = " + positiveCount);

System.out.println("\n Total Number of Negative Numbers in this Array = " + negativeCount);

}

}

i hope it will help you and plzz mark as brilent....

and msg me....

Similar questions