I'm trying to do four operations.
Find the minimum including 0 # (working on)
find the sum of the negative # (Think I'm done)
Find the sum of the odd # (working on)
How many positive #(working on)
I need help on the sum of negative
This is what will be inputed 4 2 0 1 3
this is what i get
Program Output
The minimum integer is 2
The sum of the negative integers is 0
The sum of the odd integers is 0
The number of positive integers in the sequence is 2Expected Output
The minimum integer is 0
The sum of the negative integers is 0
The sum of the odd integers is 0
The number of positive integers in the sequence is 2
import java.util.Scanner; // use the Scanner class located in the "java.util" directory
public class Assignment2
{
public static void main (String[] args)
{
int num, min,max, odd=0 ,sum=0,count = 0;
int MAX = 2147483647;//Maximun number one can input
Scanner scan = new Scanner(System.in);
num = scan.nextInt();
max = num;
min = num;
while( num != 0)// using all numbers your program reads (including the last number 0), you need to compute the minimum
{
if(num> MAX)
num = MAX;
if(num > max)
max = num;
if(num < min)
min = num;
if (num < 0)// sum of only negative integers (integers that are less than 0)
sum+= num;
if (num%2 != 0 ) //sum of odd integers (integers that cannot be divided by 2, you can use "num%2 != 0")
odd+=num;
if(num > 0) // count how many positive integers (integers that are greater than 0) in the sequence.
count ++;
num = scan.nextInt();
}
System.out.println("The minimum integer is " + min);
System.out.println("The sum of the negative integers is " + sum);
System.out.println("The sum of the odd integers is " + odd);
System.out.println("The number of positive integers in the sequence is " + count);
}
}