Computer Science, asked by rishika5518, 3 months ago

/* pro2 pg 230 */
import java.util.Scanner;
class pro2pg230
{
public static void main(String args[])
{
Scanner sc= new Scanner(System.in);
int n,i,a=0,c=0,b=0,d=0;
System.out.println("Enter 50 numbers");
for( i = 1;1<=50;i++)
{
n= sc.nextInt();
if(n>= 0)
{ a=a+n;
c++;
System.out.println("positive numbers are" + n); }
else
{
b=b+n;
d++;
System.out.println("negative numbers are" + n);
}
}
System.out.println("Sum of positives numbers are" + a);
System.out.println("Sum of negative numbers are" + b);
System.out.println("Count of positives numbers are" + c);
System.out.println("Count of negative numbers are" + d);
}}
What's error in this? please don't spam.
Question is to input any 50 numbers and display and count the sum of positive and negative number.
PLEASE DON'T SPAM​

Answers

Answered by AnindaBasu
1

Answer:

import java.util.Scanner;

class pro2pg230

{

public static void main(String args[])

{

Scanner sc= new Scanner(System.in);

int n,i,a=0,c=0,b=0,d=0;

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

for( i = 1;1<=50;i++)

{

n= sc.nextInt();

if(n>= 0)

{ a=a+n;

c++;

System.out.println("positive numbers are" + n);

}

else

{

b=b+n;

d++;

System.out.println("negative numbers are" + n);

}

}

System.out.println("Sum of positives numbers are" + a);

System.out.println("Sum of negative numbers are" + b);

System.out.println("Count of positives numbers are" + c);

System.out.println("Count of negative numbers are" + d);

}}

Similar questions