Computer Science, asked by ananyabhattacharya58, 4 months ago

Write a program to input any 50 numbers (including positive and negative).

Perform the following tasks:

(a) Count the positive numbers

(b) Count the negative numbers

(c) Sum of positive numbers

(d) Sum of negative numbers​

Answers

Answered by abhinabchoudhury29
3

Explanation:

package mypackage;

import java.util.Scanner;

public class p6 {

public static void main(String[] args) {

Scanner obj=new Scanner(System.in);

int i,countp=0;

int countn=0;

double sum=0.0,sub=0.0;

double[] a=new double[50];

for(i=0;i<50;i++){

System.out.print("Enter a possible number which include position and negative Integers: ");

a[i]=obj.nextDouble();

}

for(i=0;i<50;i++){

if(a[i]>1){

sum=sum+a[i];

countp++;

}

if(a[i]<1){

sub=sub+a[i];

countn++;

}

}

System.out.println("The addition of The positive numbers is: "+sum);

System.out.println("The addition of The negative numbers is: "+sub);

for(i=0;i<50;i++){

if(a[i]>1){

System.out.println(a[i]);

}

if(a[i]<1){

System.out.println(a[i]);

}

}

System.out.println("There are "+countp+" Positive numbers.");

System.out.println("There are "+countn+" Negative numbers.");

}

}

I would have posted the output photo too but the numbers of iterations were very huge

Here I hava used array type variable but you can do this by other methods by as per the huge number of input I had used Array variable.

please give my answer the Brainlyiest answer

Attachments:
Similar questions