so I am trying to write a small, simple program to ask the user to input 5 integers; they can be either positive or negative.
after 5 have been entered I want to output the results as
"the sum of the positive integers you entered ="
and
"the sum of the negative integers you entered ="
so far I have this and am now at a loss
package week2;
import java.util.Scanner;
public class Week2 {
public static void main(String[] args) {
Scanner kybd = new Scanner(System.in);
System.out.print("Please enter first number, + or - : ");
int num1 = kybd.nextInt();
System.out.print("Please enter second number, + or - : ");
int num2 = kybd.nextInt();
System.out.print("Please enter third number, + or - : ");
int num3 = kybd.nextInt();
System.out.print("Please enter fourth number, + or - : ");
int num4 = kybd.nextInt();
System.out.print("Please enter fifth number, + or - : ");
int num5 = kybd.nextInt();
if (num1 > 0)
{pos++;}
else
{neg++;}
System.out.println("sum of positive numbers entered is :" + pos);
System.out.println("sum of negative numbers entered is :" + neg);
}
}
can anyone point me in the correct direction ?
after 5 have been entered I want to output the results as
"the sum of the positive integers you entered ="
and
"the sum of the negative integers you entered ="
so far I have this and am now at a loss

package week2;
import java.util.Scanner;
public class Week2 {
public static void main(String[] args) {
Scanner kybd = new Scanner(System.in);
System.out.print("Please enter first number, + or - : ");
int num1 = kybd.nextInt();
System.out.print("Please enter second number, + or - : ");
int num2 = kybd.nextInt();
System.out.print("Please enter third number, + or - : ");
int num3 = kybd.nextInt();
System.out.print("Please enter fourth number, + or - : ");
int num4 = kybd.nextInt();
System.out.print("Please enter fifth number, + or - : ");
int num5 = kybd.nextInt();
if (num1 > 0)
{pos++;}
else
{neg++;}
System.out.println("sum of positive numbers entered is :" + pos);
System.out.println("sum of negative numbers entered is :" + neg);
}
}
can anyone point me in the correct direction ?
Last edited: